Skip to content

Instantly share code, notes, and snippets.

@mike-burns
Created December 13, 2011 05:08
Show Gist options
  • Save mike-burns/1470690 to your computer and use it in GitHub Desktop.
Save mike-burns/1470690 to your computer and use it in GitHub Desktop.
latte art
class Coffee
def cost
2.0
end
def origin
"Columbia"
end
end
class MilkDecorator
def initialize(drink)
@drink = drink
end
def cost
@drink.cost + 0.4
end
def method_missing(meth, *args)
if @drink.respond_to?(meth)
@drink.send(meth, *args)
else
super
end
end
def respond_to?(meth)
@drink.respond_to?(meth)
end
end
class SugarDecorator
def initialize(drink)
@drink = drink
end
def cost
@drink.cost + 0.2
end
def method_missing(meth, *args)
if @drink.respond_to?(meth)
@drink.send(meth, *args)
else
super
end
end
def respond_to?(meth)
@drink.respond_to?(meth)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment