ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:123122] [Ruby Feature#21556] Add true? and false? methods to NilClass, TrueClass, FalseClass, and String
@ 2025-08-29 17:28 Phalado (Raphael Cordeiro) via ruby-core
  2025-08-29 22:50 ` [ruby-core:123129] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Phalado (Raphael Cordeiro) via ruby-core @ 2025-08-29 17:28 UTC (permalink / raw)
  To: ruby-core; +Cc: Phalado (Raphael Cordeiro)

Issue #21556 has been reported by Phalado (Raphael Cordeiro).

----------------------------------------
Feature #21556: Add true? and false? methods to NilClass, TrueClass, FalseClass, and String
https://bugs.ruby-lang.org/issues/21556

* Author: Phalado (Raphael Cordeiro)
* Status: Open
----------------------------------------
Sometimes we need to check for an exact `true` or `false` value. This can be a string or a boolean value.

Usually, what I do to solve this is something like `value.to_s == true`, this way covering for strings, booleans, and nil values.

The idea of these new methods is to check for the exact value, being it a String, a Boolean, or even a Nil value.

This is the result obtained:

``` ruby
# String

'true'.true? # true
'false'.true? # false
''.true? # false

'true'.false? # false
'false'.false? # true
''.false? # false

# Boolean

true.true? # true
true.false? # false

false.true? # false
false.false? # true

# Nil

nil.true? # false
nil.false? # false
```




-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-14  1:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-29 17:28 [ruby-core:123122] [Ruby Feature#21556] Add true? and false? methods to NilClass, TrueClass, FalseClass, and String Phalado (Raphael Cordeiro) via ruby-core
2025-08-29 22:50 ` [ruby-core:123129] " nobu (Nobuyoshi Nakada) via ruby-core
2025-08-30 22:58 ` [ruby-core:123139] " Phalado (Raphael Cordeiro) via ruby-core
2025-08-31  0:00 ` [ruby-core:123140] " austin (Austin Ziegler) via ruby-core
2025-09-01  0:54 ` [ruby-core:123149] " shan (Shannon Skipper) via ruby-core
2025-09-01 13:44 ` [ruby-core:123157] " Phalado (Raphael Cordeiro) via ruby-core
2025-09-01 13:50 ` [ruby-core:123158] " Phalado (Raphael Cordeiro) via ruby-core
2025-09-14  1:30 ` [ruby-core:123245] " nobu (Nobuyoshi Nakada) via ruby-core
2025-09-14  1:35 ` [ruby-core:123246] " nobu (Nobuyoshi Nakada) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).