Skip to content

Instantly share code, notes, and snippets.

@tlux
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save tlux/9598242 to your computer and use it in GitHub Desktop.

Select an option

Save tlux/9598242 to your computer and use it in GitHub Desktop.
Rails: Implementation of Object#to_b to convert any value to Boolean in Rails (uses ActiveRecord Boolean Mappings)
class Object
def to_b
self.in?(ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES)
end
alias_method :to_bool, :to_b
end
# This is an initializer to load all Core Extensions in your Rails App
Dir[Rails.root.join('lib/core_ext/*.rb')].each do |file|
require file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment