Skip to content

Instantly share code, notes, and snippets.

@jkongie
Created August 5, 2010 01:55
Show Gist options
  • Save jkongie/509099 to your computer and use it in GitHub Desktop.
Save jkongie/509099 to your computer and use it in GitHub Desktop.
Dynamically define methods
# 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