Skip to content

Instantly share code, notes, and snippets.

@paneq
Created April 6, 2012 17:21
Show Gist options
  • Save paneq/2321466 to your computer and use it in GitHub Desktop.
Save paneq/2321466 to your computer and use it in GitHub Desktop.
dynamic role AndrzejKrzywda way?
class Person
def role(obj)
obj.role_for = self # if role object needs it
@roles << obj
end
def unrole(obj)
@roles.delete(obj)
end
def method_missing(method)
role = @roles.find{|r| r.respond_to?(method) }
role ? return role.send(method) : super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment