From: Keith Lancaster Date: 2006-05-11T02:24:22+09:00 Subject: Re: Newbie question about initialize methods in subclasses Wes Gamble wrote: > All, > > I just seem to have had a revelation about how the super keyword in Ruby > is ever so slightly different from the super keyword in Java. > > In general, given > > class B < A > > and desiring to add an initialize method to B, is it a "best practice" > to always do > > class B > ... > def initialize > super > ... custom B initialization here ... > end > > Basically, I'm trying to understand that if I instantiate B, then > A.initialize doesn't get called by default - is that correct? Is that > so that B can completely override the initialization details of itself? > > Thanks, > Wes A.intialize does not get called by default - you do have to call super. This is not unique to the initialize method AFAIK. If you override any method with the same signature, you must call super to invoke the previous version (up the chain). BTW, Ruby for Rails by David Black has a very clear description of method lookup that I just happened to be reading this morning. So its his fault if I'm wrong about this :-) Keith -- Posted via http://www.ruby-forum.com/.