class Tortilla
attr_accessor :meat, :vegetables, :sauce
def initialize
@vegetables = []
end
end
class Chicken; end
class Mutton; end
class Cucumber; end
class Onion; end
class Tomato; end
class MildSauce; end
class SpicySauce
attr_reader :level
def initialize(level)
@level = level
end
end
class TortillaBuilder
attr_reader :tortilla
def initialize(tortilla)
@tortilla = tortilla
end
def select_chicken
tortilla.meat = Chicken.new
end
def select_mutton
tortilla.meat = Mutton.new
end
def add_cucumber
tortilla.vegetables << Cucumber.new
end
def add_tomato
tortilla.vegetables << Tomato.new
end
def add_onion
tortilla.vegetables << Onion.new
end
def select_garlic_sauce
tortilla.sauce = GarlicSauce.new
end
def select_spicy_sauce(level = :hot)
tortilla.sauce = SpicySauce.new(level)
end
end
builder = TortillaBuilder.new(Tortilla.new)
builder.select_chicken
builder.add_cucumber
builder.add_cucumber
builder.add_tomato
builder.select_spicy_sauce(level: :extra_hot)