Created
April 8, 2014 10:19
-
-
Save qoobaa/10107191 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = %w[admin manager client] | |
validates :role, inclusion: {in: ROLES} | |
def role | |
ActiveSupport::StringInquirer.new(self[:role].to_s) | |
end | |
end | |
user = User.create!(role: "manager") | |
user.role.admin? # => false | |
user.role.manager? # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment