Skip to content

Instantly share code, notes, and snippets.

@mmattice
Forked from jriddy/register_methods.py
Last active December 15, 2015 17:19
Show Gist options
  • Save mmattice/6adada2509f1d94ec336 to your computer and use it in GitHub Desktop.
Save mmattice/6adada2509f1d94ec336 to your computer and use it in GitHub Desktop.
# Test on delivery
def register(key):
def decorator(method):
method.response = key
return method
return decorator
@register('$')
def msgtype_DOLLARSIGN(self, blah):
pass
class Whatever(object):
def __init__(self):
self.registry = {}
for x in (getattr(self, k) for k in dir(self)):
if callable(x) and hasattr(x, 'response'):
self.registry.update({getattr(x, 'response'): x})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment