Skip to content

Instantly share code, notes, and snippets.

@rik0
Created April 15, 2012 15:27
Show Gist options
  • Save rik0/2393423 to your computer and use it in GitHub Desktop.
Save rik0/2393423 to your computer and use it in GitHub Desktop.
Funny decorator
import functools
class rusty_method(object):
def __init__(self, hits, chain_effect):
self.hits = hits
self.chain_effect = chain_effect
self.hit_memory = []
def __call__(self, func):
def aux(that, *args):
self.hit_memory.append(args)
if self.hits > 0:
self.hits -= 1
else:
cols = zip(*self.hit_memory)
self.hit_memory.pop()
arguments = [reduce(self.chain_effect, col)
for col in cols]
return func(that, *arguments)
functools.update_wrapper(aux, func)
return aux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment