Skip to content

Instantly share code, notes, and snippets.

@lukehinds
Created July 19, 2015 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukehinds/15c9e07ae81aff2dc010 to your computer and use it in GitHub Desktop.
Save lukehinds/15c9e07ae81aff2dc010 to your computer and use it in GitHub Desktop.
class Pizza(object):
def __init__(self):
self.toppings = []
def __call__(self, topping):
# when using '@instance_of_pizza' before a function def
# the function gets passed onto 'topping'
self.toppings.append(topping())
def __repr__(self):
return str(self.toppings)
pizza = Pizza()
@pizza
def cheese():
return 'cheese'
@pizza
def sauce():
return 'sauce'
print pizza
# ['cheese', 'sauce']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment