Albert Wagner <alwagner / tcac.net> 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
> 	        <more>
> 	        super(a, x, y, z, <more>)
> 	    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