Generally, you would use the Kernel#method
method to get the Method
object for the method in question and then you would use the Method#owner
method to ask the Method
object where it was defined.
So,
req.method(:basic_auth).owner
# => Net::HTTPHeader
should answer your question.
Except, in this particular case, that won't work because req
is a Net::HTTP::Get
object and Net::HTTP::Get
overrides the method
method to mean something completely different. In particular, it doesn't take an argument, thus the above code will actually raise an ArgumentError
.
However, since Net::HTTP::Get
inherits from Object
and Object
mixes in Kernel
, it is legal to bind the Kernel#method
method to an instance of Net::HTTP::Get
:
Kernel.instance_method(:method).bind(req).(:basic_auth).owner
# => Net::HTTPHeader
So, there's your answer: the method is defined in Net::HTTPHeader
.
req.method(:basic_auth).owner
- but this doesn't work here becausemethod
has been redefined inNet::HTTP::Get
...Kernel.method
onNet::HTTP::Get
so redefinition will not interfere?method
's receiver should be the object which receives the method you're interested in (because it wants to bind the method). But perhaps you can find something I can't.