Class: String
Instance Method Summary collapse
-
#parse_bool ⇒ true, false
Returns the parsed value of this object.
-
#parse_bool! ⇒ true, false
Similar to #parse_bool, but raises an error unless the string can be explicitly parsed to @true@ or @false@.
- #to_b ⇒ Object
- #to_b! ⇒ Object
Instance Method Details
#parse_bool ⇒ true, false
Returns the parsed value of this object. Strings beginning with any of “y”, “t”, or “1” are considered @true@, whereas all else are considered @false@.
76 |
# File 'lib/boolean.rb', line 76 def parse_bool() %w( y Y 1 t T ).include? self[0,1] end |
#parse_bool! ⇒ true, false
Similar to #parse_bool, but raises an error unless the string can be explicitly parsed to @true@ or @false@. Strings beginning with “n”, “f”, or “0” are considered false.
92 93 94 95 96 97 98 99 100 |
# File 'lib/boolean.rb', line 92 def parse_bool! if %w( y Y 1 t T ).include? self[0,1] then true elsif %w( n N 0 f F ).include? self[0,1] then false else raise ArgumentError, "Invalid value for parse_bool!: #{inspect}" end end |