Skip to content

Instantly share code, notes, and snippets.

@rachidcalazans
Created September 29, 2018 03:37
Show Gist options
  • Save rachidcalazans/d85fbb2178f9e5d66040beae35033311 to your computer and use it in GitHub Desktop.
Save rachidcalazans/d85fbb2178f9e5d66040beae35033311 to your computer and use it in GitHub Desktop.
Design Patterns in Ruby - Template Method
class CaffeineBeverage
def prepare_recipe
# Abstract method without implementation
end
def boil_water
puts 'boil water'
end
def pour_in_cup
puts 'pour in cup'
end
end
class Cappuccino < CaffeineBeverage
def prepare_recipe
boil_water
brew_cappuccino_grinds
pour_in_cup
add_sugar
end
def brew_cappuccino_grinds
puts 'brew cappuccino grinds'
end
def add_sugar
puts 'add sugar'
end
end
class Tea < CaffeineBeverage
def prepare_recipe
boil_water
steep_the_bag
pour_in_cup
add_lemon
end
def steep_the_bag
puts 'steep the bag'
end
def add_lemon
puts 'add lemon'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment