Skip to content

Instantly share code, notes, and snippets.

@maruno
Forked from jcberthon/string_ext.rb
Last active December 15, 2015 12:39
Show Gist options
  • Save maruno/5261975 to your computer and use it in GitHub Desktop.
Save maruno/5261975 to your computer and use it in GitHub Desktop.
Ruby String to_boolean monkey patch with Dutch i18n
class String
def to_boolean
return true if self == true || self =~ (/(true|t|yes|y|1|ja)$/i)
return false if self == false || self.nil? || self.empty? || self =~ (/(false|f|no|n|0|nee)$/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