Skip to content

Instantly share code, notes, and snippets.

@patricksrobertson
Created May 17, 2011 18:50
Show Gist options
  • Save patricksrobertson/977099 to your computer and use it in GitHub Desktop.
Save patricksrobertson/977099 to your computer and use it in GitHub Desktop.
class Coffee
def cost
3.00
end
end
class SprinkledCoffee
def initialize(coffee)
@base_cost = coffee.cost
end
def cost
@base_cost + 1.50
end
end
class WhippedCoffee
def initialize(coffee)
@base_cost = coffee.cost
end
def cost
@base_cost + 2.00
end
end
my_coffee = Coffee.new
my_coffee.cost # => 3.00
fancier_coffee = SprinkledCoffee.new(my_coffee)
fancier_coffee.cost # => 4.50
fanciest_coffee = WhippedCreamCoffee.new(SprinkledCoffee.new(my_coffee))
fanciest_coffee.cost # => 6.50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment