From: Paul Lutus Date: 2006-12-06T19:45:11+09:00 Subject: Re: Calling super in overwritten methods Joerg Diekmann wrote: > Hi - not sure if this is possible - but it feels like it could be with > some serious ruby-fu. > > I have the following: > > class A > def method1 > method2 > end > > def method2 > return 100 > end > end > > class B < A > def method1 > super > end > > def method2 > return 200 > end > end > > > This is what happens: > > b.method1 # 200 > > But, what I want is: > > b.method1 # 100 > > > Is this possible at all? No, not without some tortured coding. You have redefined method2 in your derived class, consequently this redefinition takes precedence in instances of the derived class, and this is by design, not by accident. Remember that the call to "method2" in the parent class, called with "super" as you show it, is still in the context of an instance of the derived class, so the call is resolved to refer to the derived class method2, not the parent one. If, as you say, you really want the result of the parent's method2, then don't redefine that method in the derived class. Or use different method names to create the distinction you want. -- Paul Lutus http://www.arachnoid.com