Created
August 5, 2010 01:55
-
-
Save jkongie/509099 to your computer and use it in GitHub Desktop.
Dynamically define methods
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
# Dynamically define whether a user has a role methods in a nice query language based on User::ROLES | |
# Eg. Can now call user.admin? or user.billing? | |
ROLES.each do |role| | |
method_name = (role + '?').to_sym | |
send :define_method, method_name do | |
self.role == role | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment