Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string_to_bool.rb

Instance Method Summary collapse

Instance Method Details

#to_boolObject

Raises:

  • (ArgumentError)


4
5
6
7
8
# File 'lib/string_to_bool.rb', line 4

def to_bool
  return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
  return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
  raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end