Created
April 6, 2012 17:21
-
-
Save paneq/2321466 to your computer and use it in GitHub Desktop.
dynamic role AndrzejKrzywda way?
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 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