Created
April 5, 2013 22:40
-
-
Save udit99/5323252 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
module Cookable | |
def make_into dish | |
dish.make_into self | |
end | |
def to_s | |
self.class.to_s | |
end | |
end | |
class Chicken | |
include Cookable | |
end | |
class Beef | |
include Cookable | |
end | |
class Sandwich | |
def make_into meat | |
puts "#{meat} Sandwich" | |
end | |
end | |
class Stew | |
def make_into meat | |
puts "#{meat} Stew" | |
end | |
end | |
class Casserole | |
def make_into meat | |
puts "#{meat} Casserole" | |
end | |
end | |
class Restaurant | |
def initialize meat | |
@meat = meat | |
end | |
def make_sandwich | |
@meat.make_into Sandwich.new | |
end | |
def make_stew | |
@meat.make_into Stew.new | |
end | |
def make_casserole | |
@meat.make_into Casserole.new | |
end | |
end | |
smokies = Restaurant.new(Chicken.new) | |
smokies.make_sandwich | |
smokies.make_stew | |
smokies.make_casserole | |
smokies = Restaurant.new(Beef.new) | |
smokies.make_sandwich | |
smokies.make_stew | |
smokies.make_casserole |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment