class Drink
attr_reader :glass, :alcohol, :additions
def initialize
@glass = prepare_glass
@alcohol = add_alcohol
@additions = add_additions
end
def prepare_glass
raise NoMethodError
end
def add_alcohol
raise NoMethodError
end
def add_additions
raise NoMethodError
end
end
class WhiskyDrink < Drink
def prepare_glass
Glass.new(size: 200)
end
def add_alcohol
Whisky.new
end
def add_additions
[Ice.new, Ice.new, Lime.new]
end
end
class VodkaDrink < Drink
def prepare_glass
Glass.new(size: 40)
end
def add_alcohol
Vodka.new
end
def add_additions
nil
end
end
# Real implementations of those classes are not important for this example.
class Vodka; end
class Whisky; end
class Ice; end
class Lime; end
class Glass
attr_reader :size
def initialize(size: nil)
@size = size
end
end
vodka = VodkaDrink.new
whisky = WhiskyDrink.new
vodka.glass.size # => 40