comparison python/bind.py @ 264:efeb2cc78f30

stub this motha
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 17 Feb 2013 12:46:25 -0800
parents 7b15ed0b372c
children
comparison
equal deleted inserted replaced
263:7b15ed0b372c 264:efeb2cc78f30
7 class Foo(object): 7 class Foo(object):
8 8
9 @classmethod 9 @classmethod
10 def create(cls): 10 def create(cls):
11 """create an instance and bind a method onto foo""" 11 """create an instance and bind a method onto foo"""
12 12 class decorator(object):
13 def __init__(self, function):
14 self.function = function
15 def __call__(self):
16 print "Bar!"
17 return self.function()
18
19 instance = cls()
20 instance.foo = decorator(instance.foo)
21 return instance
13 22
14 def foo(self): 23 def foo(self):
15 print "Foo!" 24 print "Foo!"
16 25
26 if __name__ == '__main__':
27 foo = Foo.create()
28 foo.foo()