From: Nathan Smith Date: 2006-08-24T23:57:54+09:00 Subject: Re: Call functions of superclass Hello, On Thu, 24 Aug 2006 dblack@wobblini.net wrote: > No; it will point to the superclass of the class of self :-) > > class C > end > class D < C > end > D.new.class.superclass # C I think we are using different terminology. Take a look at this code: class A def A.hi puts "A.hi" end def hi puts "hi" end end class B < A def hi self.class.superclass.hi end end b = B.new b.hi This will output A.hi In "Programming Ruby", they define the "metaclass" as the object which contains the class-wide objects of the class. IE, the metaclass of A would contain A.hi, and not A#hi (I could be getting the notation of A.hi and A#hi backwards, or completely wrong -- A.hi is the class method, and A#hi is the instance method.) Therefore, in B#hi, self.class.superclass does not refer to the superclass of B -- rather it refers to the metaclass of the super of B. If it pointed to the superclass of B, then calling self.class.superclass.hi would print "hi", instead of "A.hi" > > This isn't what is wanted when calling super.someMethod (that would > > be like doing super.class.someMethod, which is different). I > > recognize Ruby is different from other langauges, but many other > > languages (even less OO capable languages such as Java and C++) have > > the use of the "super.someMethod" functionality. > > Well... it's probably good that Ruby isn't a superset of those less OO > capable languages :-) I'm not suggesting that Ruby be a superset of those languages (and I'm glad it isn't) -- I'm suggesting that the other languages got the terminology right in using both the "self" and the "super" keywords in the same context. > But I'm getting confused by the use of an existing keyword to describe a > new concept. Also, it's not clear what the keyword would actually > produce. You're sending the someMethod message to it, but from what I > understand you don't really mean it to respond to that method, but > rather to re-send the message to the current self, using the constraint > that the currently visible version of the method be skipped. I do want the message to be responded to. Calling super.someMethod would pass the someMethod message to the super object. The message is not being re-sent to any object, nor is it being routed through any object. It is being sent directly to the super object. "super" would either point to the superclass of self (the instance version), or (in the case of self.class.super), would refer to the metaclass of the superclass of self. Perhaps Matz wants to keep the metaclass completely hidden from the programmer (indeed, it is hinted so in Programming Ruby), and I can see the merits in doing so. This still requires more work for the programmer to be able to perform what was stated earlier in this thread. Nate