From: Matt Armstrong Date: 2002-01-10T09:14:45+09:00 Subject: Re: How to override subclass#new Albert Wagner writes: > I have some code similar to below, which expresses my intent, but is > not what is happening. Who is calling B#initialize? Do I need a > call to super in B#initialise? I keep getting trash in the b and c > passed to B#initialize or error messages saying that there are too > many args being passed to B#initialize. I obviously have a very > murky understanding of how to achieve what I want. Thanks ahead for > any advice. > > class A > def A.new(a, *args) > end > end > > class B < A > def B.new(a, b, c) > x = 1 > y = 2 > z = 3 > > super(a, x, y, z, ) > end > def initialize(a, b, c) > @a = a > @b = b > @c = c > end > end > > B.new(a,b,c) #<==preferred method of creating a B instance I am not actually sure what you want, since the only way you show it is with code that does not work. ;-) But in Ruby, you usually do not override a class' new method. Instead just override initialize and call super within initialize. -- matt