Skip to content

Instantly share code, notes, and snippets.

@erskingardner
Created August 4, 2011 07:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save erskingardner/1124645 to your computer and use it in GitHub Desktop.
Save erskingardner/1124645 to your computer and use it in GitHub Desktop.
Convert String to Boolean value
class String
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
end
@stevenhaddox
Copy link

Still useful three years later >.<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment