Skip to content

Instantly share code, notes, and snippets.

@rvanlieshout
Created March 4, 2011 09:19
Show Gist options
  • Save rvanlieshout/854380 to your computer and use it in GitHub Desktop.
Save rvanlieshout/854380 to your computer and use it in GitHub Desktop.
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