Skip to content

Instantly share code, notes, and snippets.

@tihuan
Created July 31, 2014 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tihuan/dc18a9429370da4af9d2 to your computer and use it in GitHub Desktop.
Save tihuan/dc18a9429370da4af9d2 to your computer and use it in GitHub Desktop.
class Coffee
def cost
2
end
def origin
"Colombia"
end
end
class Milk
def initialize(component)
@component = component
end
def cost
@component.cost + 0.4
end
end
coffee = Coffee.new
Sugar.new(Milk.new(coffee)).cost # 2.6
Sugar.new(Sugar.new(coffee)).cost # 2.4
Sugar.new(Milk.new(coffee)).class # Sugar
Milk.new(coffee).origin # NoMethodError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment