David Walker
11/8/2006 3:03:00 AM
On 11/7/06, dblack@wobblini.net <dblack@wobblini.net> wrote:
> The fact that B can call A.class_method is due to the special-casing
> of singleton classes of Class objects; it's the one case where a given
> object can execute singleton methods of another object. But those
> singleton methods still belong, unambiguously, to the first object, A.
> The reason B can call them is that A's singleton class serves as the
> superclass of B's singleton class -- so class_method lies on the
> method look-up path of B. But class_method is still defined only in
> A's singleton class.
Thanks for the info. That's mostly what I thought - I guess I should
have said, "This seems silly to me," not, "This doesn't make sense to
me." :)
How, though, is this a special case? For instance methods, you can
bind an instance method to any object who's class is <= the class the
method is defined on. Why should it be different for singletons? I.e.
I have an instance method (instance from the perspective of the
singleton class A), I should be able to bind it to an object who's
class is a subclass of the class the instance is defined on. If A's
singleton class is a superclass of B's singleton class (which it ought
to be) then this relation holds. I think. :)
In any case, "B.method(:class_method)" gave me a #<Method:
B(A).class_method>. My original question still stands: is there no way
to recover this binding once it's been unbound?
--
=D ave