On Oct 10, 6:19=A0pm, Charles Oliver Nutter <charles.nut... / sun.com>
wrote:
> christofore... / gmail.com wrote:
> > While playing around with ruby threads I noticed that if you dont call
> > super when subclassing a thread you will get an initialization error.
> > So ok we throw a super in the initialize method and that clears things
> > up. Unfortunately if you put super as the first line in the initialize
> > method the rest of the initialize will not execute but the block which
> > is part of the initial thread creation gets initialized. However if
> > you put super as the last statement in the initialize method, the
> > whole initialize gets executed and then the block from the thread
> > creation gets executed. Does anyone else find this a bit funny? And
> > what is a good practice when subclassing thread... to put super first
> > or last statement in the initialize method? and is there any benefit
> > for either?
>
> I'll echo others' concerns about why you're doing this, but if the
> initialize chain causes you headaches you could always redefine new for
> your class:
>
> class MyThread < Thread
> =A0 =A0def self.new(arg1, arg2)
> =A0 =A0 =A0super {
> =A0 =A0 =A0 =A0Thread.current[:arg1] =3D arg1
> =A0 =A0 =A0 =A0Thread.current[:arg2] =3D arg2
> =A0 =A0 =A0 =A0yield
> =A0 =A0 =A0}
> =A0 =A0}
>
> }
>
> It would probably be better put in a separate data structure that spins
> up a Thread internally though.
>
> - Charlie

Thank you to everyone who has responded and for your insight. Coming
from a java threading background I simply assumed that creating a new
sub-classed thread would run the constructor and then the following
run method. Thank you for the comments however they are much
appreciated and allowed me to see a different point of view.

Sincerely,
Chris Dancy