Created
January 5, 2012 03:36
-
-
Save lcowell/1563581 to your computer and use it in GitHub Desktop.
This file contains 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
# Say you have different types of pet classes. It appears that using method_missing is preferable | |
# over using DelegateClass as we can decide our target at runtime. Is there a way to accomplish | |
# this type of behaviour using DelegateClass ? | |
def PetDecorator | |
def initialize(target) | |
@target = target | |
end | |
def talk | |
"-->" + super | |
end | |
def self.method_missing(method, *args, &block) | |
@target.send(method, args, &block) | |
end | |
end | |
PetDecorator.new(Cat.new) | |
PetDecorator.new(Dog.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment