Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails: convert anything to boolean
# config/initializers/to_boolean.rb
module ToBoolean
def to_bool
return true if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self)
return false
end
end
class NilClass; include ToBoolean; end
class TrueClass; include ToBoolean; end
class FalseClass; include ToBoolean; end
class Numeric; include ToBoolean; end
class String; include ToBoolean; end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment