From: jvivenot Date: 2006-08-21T07:25:11+09:00 Subject: Re: Initialize and superclass Actually, it seems that I if I write only super because the super initialize needs no argument, the super method gives every arguments of the B class to the A initialize, and thus I encounter a ArgumentError. That's OK Thanks Julien Vivenot jvivenot wrote: > 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/.