class String
Public Instance Methods
parse_bool()
click to toggle source
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@.
@return [true, false] The parsed Boolean
value of this string. @see parse_bool!
# File lib/boolean.rb, line 76 def parse_bool() %w( y Y 1 t T ).include? self[0,1] end
parse_bool!()
click to toggle source
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.
@return [true, false] The parsed Boolean
value of this string. @raise [ArgumentError] If the string does not seem to represent @true@ or
@false@.
@example
"true".parse_bool! #=> true "no".parse_bool! #=> false "maybe".parse_bool! #=> ArgumentError
# 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
to_b()
click to toggle source
@see parse_bool
# File lib/boolean.rb, line 79 def to_b() parse_bool end
to_b!()
click to toggle source
@see parse_bool!
# File lib/boolean.rb, line 103 def to_b!() parse_bool! end