Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. class User
  2. Role = Struct.new(:label, :short_label)
  3. ROLES = {
  4. "hr_manager" => Role.new("HR Manager", "manager"),
  5. "benefits_broker" => Role.new("Benefits Broker", "broker")
  6. }
  7.  
  8. def role
  9. ROLES[attributes["role"]]
  10. end
  11.  
  12. delegate :label, :short_label, to: :role, prefix: true
  13. end
  14.  
  15. # Now, you can do the following to access the label and short label:
  16. user.role_label
  17. user.role_short_label
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement