Skip to content

Instantly share code, notes, and snippets.

@jcberthon
Forked from erskingardner/string_ext.rb
Created June 12, 2012 10:49
Show Gist options
  • Save jcberthon/2916857 to your computer and use it in GitHub Desktop.
Save jcberthon/2916857 to your computer and use it in GitHub Desktop.
Convert String to Boolean value
class String
def to_boolean
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
return false if self == false || self.nil? || self.empty? || self =~ (/(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment