How in the world does SimpleDelegator#method work?
SimpleDelegatorsubclassesBasicObject, which does not provide amethodmethod.- Looking over the
source,
you can see that it doesn't define a
methodmethod anywhere. - It does define
method_missingand proxy undefined methods to the delegated object...but I don't think that can be how it works, because both of these examples work:
class MyProxy < SimpleDelegator
def undelegated
:undelegated
end
end
p = MyProxy.new(:some_object)
p.method(:undelegated).callSimpleDelegator.new(BasicObject.new).method(:object_id)In the first example, it can't be proxying method to the
:some_object because :some_object does not have an
undelegated method. In the second example, it can't
be proxying to the BasicObject because BasicObject
lacks a method method, as already mentioned.
So how in the world does this work?
@alindeman already pointed out that it comes from Kernel on twitter, but you can just ask
#methodwhere#methodcomes from: