From: dblack@... Date: 2006-11-08T12:39:00+09:00 Subject: Re: Can't bind a singleton method to a subclass? Hi -- On Wed, 8 Nov 2006, ara.t.howard@noaa.gov wrote: > On Wed, 8 Nov 2006 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. > > still, quiet odd that one can do this > >>> p B.method(:class_method).unbind > > meaning, it's strange that you can 'unbind' from a class something which > cannot be bound to it and yet must have been for the initial call to > 'unbind' > to succeed - a contradiction. I think it's not so much that you're unbinding it *from* B, as that you're grabbing it *through* B. So, by the time you unbind it, it doesn't "know" that you got it that way; it's just a Method object, and it allows itself to be unbound. I'd say that's a side-effect of the fact that A's singleton methods can be got at via B at all. Going the other way, though, it does "know" that you're trying to bind it to something other than the object in whose singleton class it's defined. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org