lib/bootstripe/string_additions.rb in bootstripe-0.2.14 vs lib/bootstripe/string_additions.rb in bootstripe-0.2.15
- old
+ new
@@ -1,9 +1,15 @@
class String
def decapitalize
self[0, 1].downcase + self[1..-1]
end
-
+
def to_class
Object.const_get(self)
+ end
+
+ def to_bool
+ return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
+ return false if self == false || self.empty? || self =~ (/(false|f|no|n|0)$/i)
+ raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
\ No newline at end of file