Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2015 16:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Transfert enumerator accessors to related model
class User < ActiveRecord::Base
belongs_to :organization
Organization.categories.keys.each do |category|
define_method("#{category}?") do
# Organization model has an enum category with following values: admin, insurance, practice
# It generated automatically on the organization model admin?, insurance?, practice?
# To have it also on the user model (belonging to Organization), we can create dynamically this method with define_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment