Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/constructor-core.rb
Instance Method Summary collapse
Instance Method Details
#boolean? ⇒ Boolean
12 13 14 15 16 17 18 |
# File 'lib/constructor-core.rb', line 12 def boolean? if self =~ (/(true|yes)$/i) || self =~ (/(false|no)$/i) return true else return false end end |
#numeric? ⇒ Boolean
7 8 9 10 |
# File 'lib/constructor-core.rb', line 7 def numeric? return true if self =~ /^\d+$/ true if Float(self) rescue false end |
#to_bool ⇒ Object
20 21 22 23 24 |
# File 'lib/constructor-core.rb', line 20 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 |