Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created April 8, 2014 10:19
Show Gist options
  • Save qoobaa/10107191 to your computer and use it in GitHub Desktop.
Save qoobaa/10107191 to your computer and use it in GitHub Desktop.
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