Class: String

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

Instance Method Summary collapse

Instance Method Details

#to_boolObject

Adding a to_bool method



13
14
15
16
17
18
# File 'lib/mongocore/ext.rb', line 13

def to_bool
  return true if self =~ (/^(true|yes|t|y|[1-9]+)$/i)
  return false if self.empty? || self =~ (/^(false|no|n|f|0)$/i)

  raise ArgumentError.new %{invalid value: #{self}}
end