Is it (in any way, no matter how weird or ugly) possible to call an object like a method. I'm not talking about method objects or calling an object's method, I mean this:
class Klass
def callMeMethod *args
p args
end
end
myObject = Klass.new
myObject *args #=> [arg0, arg1, ...]
myObject(*args) #=> [arg0, arg1, ...]
I thought about defining a new global method each time an object is created (never mind how terrible that is) but I ran into problems, also I would ideally like to call it even if it's returned from some expression such as:
someArray[index_of_my_object] *args #=> [arg0, arg1, ...]
someArray[index_of_my_object](*args) #=> [arg0, arg1, ...]
So basically Python's __call__
method.
thanks