public
Last active — forked from erskingardner/string_ext.rb

Ruby: Convert String to Boolean

  • Download Gist
string_ext.rb
Ruby
1 2 3 4 5 6 7
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.