Created
March 4, 2011 09:19
-
-
Save rvanlieshout/854380 to your computer and use it in GitHub Desktop.
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 | |
ROLES = [ | |
'admin', | |
'manager', | |
'branch_manager', | |
'planner', | |
'employee', | |
'customer' | |
].freeze | |
# Define a method for each role: user.admin?, user.manager?, ... | |
User.class_eval do | |
User::ROLES.each do |state| | |
define_method "#{state}?" do | |
self.role == state | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment