You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kubsu-sm5-ruby/template_method.rb

57 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

class Beverage
# шаблонный метод
def prepare
boil_water
brew
pour_in_cup
add_condiments
end
# общие методы
def boil_water
puts "Кипячение воды..."
end
def pour_in_cup
puts "Наливание в чашку..."
end
def brew
raise NotImplementedError, "Метод 'brew' должен быть определён"
end
def add_condiments
raise NotImplementedError, "Метод 'add_condiments' должен быть определён"
end
end
class Tea < Beverage
def brew
puts "Заваривание чая..."
end
def add_condiments
puts "Добавление лимона..."
end
end
class Coffee < Beverage
def brew
puts "Заваривание кофе..."
end
def add_condiments
puts "Добавление сахара и молока..."
end
end
puts "☕️Приготовление чая:"
tea = Tea.new
tea.prepare
puts "\n☕️Приготовление кофе:"
coffee = Coffee.new
coffee.prepare