Created
May 17, 2011 18:50
-
-
Save patricksrobertson/977099 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
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