WoNáDo
1/20/2007 4:45:00 PM
gwtmp01@mac.com schrieb:
>
> On Jan 20, 2007, at 10:20 AM, Wolfgang Nádasi-Donner wrote:
>
>> Vincent Fourmond schrieb:
>>> gwtmp01@mac.com wrote:
>>>> Method#receiver
>>>> Method#name
>>>> Method#origin # module/class with definition of method
>>>>
>>>> Kernel#origin(name) # module/class where named method is found
>>>> # via standard method lookup process on the
>>>> # receiver.
>>>> # nil if no matching method found
>>> I vote for the last one too !
>>> Vince
>>
>> An additional method "Kernel#origin(name)" will be helpful, if the
>> method is defined as a singleton method for an object, it is difficult
>> to get the object_id of the anonymous class, where the method ist
>> defined (I hope this sentense is somehow understndable).
>>
>> The object_id is necessary in comparisons with the result of the call
>> to the method of class "Method", that returns the associated class.
>
> I was assuming that Method#origin and Kernel#origin would both
> return a reference to the class/module. In fact, Kernel#origin
> is really just short for method(name).origin and of course
> you can just call object_id on the module/class reference as needed.
>
> It appears that you are viewing the (proposed) return value of
> Method#origin and Kernel#origin as a string and not as a reference
> to the module/class itself as intended by myself and the other
> posters.
Sorry, I am a little bit confused in the moment...
What I like to say is, that in case of
class Otto
def hi
puts "Hi"
end
end
o = Otto.new
my1 = o.method(:hi) # Class Otto, Method hi
class << o
def hi
puts "Hihi"
end
end
my2 = o.method(:hi) # Class -anonymous-, Method hi
"Method#origin" returns the object_id of the class where the method belongs too.
Thats clear for me. The problem I see is, that for the second Method-object
"my2" "Method#origin" returns an object_id on an anonymous class.
If later on I want to find out if my Method objects reference a method, that is
defined in an anonymous class, I will have problems to get the object_id of this
anonymous class without an additional "Kernel#origin(name)" method, that returns
the object_id of the anonymous class in case of (e.g) "o.origin(:hi)". The
result should not be the same before and after "class << o".
Wolfgang Nádasi-Donner