From: jvivenot Date: 2006-08-21T06:50:11+09:00 Subject: Re: Initialize and superclass Wonderful ! Thanks. I think there will be many days during which I'll stay a Ruby-Nuby.... Bye, and thanks everyone Julien Vivenot Eero Saynatkari wrote: > Tilman Sauerbeck wrote: > > jvivenot [2006-08-21 01:35]: > >> Lets say I have two classes A and B, where A is B's superclass. B's > >> initialize method initialize her own variables, but how could I do in > >> order to run A.initialize before B.initialize when I write B.new ? > > > > If I understood your problem correctly, you're after the "super" method. > > Try the following code: > > > > > > And in the event that you some arguments to B that > A does not know how to handle, use the second form: > > class A > def initialize(foo) > puts "initializing instance of A with #{foo}" > end > end > > class B > def initialize(foo, bar) > super(foo) > puts "initializing instance of B with #{foo} and #{bar}" > end > end > > > Regards, > > Tilman > > -- > Posted via http://www.ruby-forum.com/.