1 class MethodMissingMixin(object):
3 A Mixin' to implement the 'method_missing' Ruby-like protocol.
5 This was `taken from a blog post <http://blog.iffy.us/?p=43>`_
7 def __getattr__(self, attr):
8 class MethodMissing(object):
9 def __init__(self, wrapped, method):
10 self.__wrapped__ = wrapped
11 self.__method__ = method
12 def __call__(self, *args, **kwargs):
13 return self.__wrapped__.method_missing(self.__method__, *args, **kwargs)
14 return MethodMissing(self, attr)
16 def method_missing(self, *args, **kwargs):
17 """ This method should be overridden in the derived class. """
18 raise NotImplementedError(str(self.__wrapped__) + " 'method_missing' method has not been implemented.")