Last active
June 13, 2017 15:30
-
-
Save tracyloisel/659f3f02d07f97121e64b488cce8e99d to your computer and use it in GitHub Desktop.
Write chainable methods at class level
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
#PizzaHut.pepperoni(6). | |
# italian_sausage_ml(20). | |
# ham(6). | |
# bacon(6). | |
# seasoned_pork_and_beef(10). | |
# deliver_to(street: "Infinite loop", city: "Cupertino", name: "Tim Cook"). | |
# go! | |
module PizzaHutClassMethods | |
def current_pizza(recipes_params = {}) | |
@__pizza ||= PizzaBuilder.new(recipes_params) | |
end | |
def pepperoni(qty) | |
current_pizza.add(pepperony: qty) | |
self | |
end | |
def ham(qty) | |
current_pizza.add(ham: qty) | |
self | |
end | |
def bacon(qty) | |
current_pizza.add(bacon: qty) | |
self | |
end | |
def seasoned_pork_and_beef(qty) | |
current_pizza.add(seasoned_pork_and_beef: qty) | |
self | |
end | |
end | |
class PizzaHut | |
extend PizzaHutClassMethods | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment