Created
December 9, 2015 16:09
-
-
Save jameslafa/a1913c5d13f42ca87168 to your computer and use it in GitHub Desktop.
Transfert enumerator accessors to related model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
belongs_to :organization | |
Organization.categories.keys.each do |category| | |
define_method("#{category}?") do | |
organization.send("#{category}?") | |
end | |
end | |
end | |
# 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