Method: String#to_b
- Defined in:
- lib/core/facets/boolean.rb
#to_b ⇒ Object
Interpret common affirmative string meanings as true, otherwise nil or false. Blank space and case are ignored. The following strings that will return true …
true
yes
on
t
1
y
==
The following strings will return nil …
nil
null
All other strings return false.
Here are some exmamples.
"true".to_b #=> true
"yes".to_b #=> true
"no".to_b #=> false
"123".to_b #=> false
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/core/facets/boolean.rb', line 96 def to_b case self.downcase.strip when 'true', 'yes', 'on', 't', '1', 'y', '==' return true when 'nil', 'null' return nil else return false end end |