How in the world does SimpleDelegator#method
work?
SimpleDelegator
subclassesBasicObject
, which does not provide amethod
method.- Looking over the
source,
you can see that it doesn't define a
method
method anywhere. - It does define
method_missing
and 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).call
SimpleDelegator.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
#method
where#method
comes from: