Skip to content

Instantly share code, notes, and snippets.

@emrekilinc
Forked from ChuckJHardySnippets/string_ext.rb
Created January 3, 2014 08:37
Show Gist options
  • Save emrekilinc/8234821 to your computer and use it in GitHub Desktop.
Save emrekilinc/8234821 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment