def extend_class(cls, method_name=None):
    """
    Decorator: add the decorated function to the specified class.
    If no name is specified the name of the function is used.

    :example:

    >>> class A:
    >>>    pass
    >>>
    >>> @extend_class(A, "shiny_method")
    >>> def hello(self, name):
    >>>     print("Hello", name)
    >>>
    >>> a = A()
    >>> a.shiny_method("foo")

    :param cls The class to extend
    :param method_name The name that the new method will take (If None, it will be determined from the decorated function)
    """

    def decorate(funct):
        tmp = method_name
        if tmp is None:
            if hasattr(funct, "__name__"):
                tmp = funct.__name__
            else:
                raise RuntimeError("Name attribute cannot be found in " + str(funct))
        setattr(cls, tmp, funct)
        return funct

    return decorate