Skip to content

Instantly share code, notes, and snippets.

@lcowell
Created January 5, 2012 03:36
Show Gist options
  • Save lcowell/1563581 to your computer and use it in GitHub Desktop.
Save lcowell/1563581 to your computer and use it in GitHub Desktop.
# 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