Hi --

On Fri, 10 Oct 2008, christoforever / 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 assume it's just how Thread#initialize is defined. If it yields to
the block, and you call it, then it will yield to the block. It's like
this:

   class C
     def initialize
       yield
     end
   end

   class D < C
     def initialize
       super
       puts "Back from calling super"
     end
   end

   D.new { puts "Inside block" }

Output:

   Inside block
   Back from calling super

It's just executing commands in the order you issue them.


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   Intro to Ruby on Rails  January 12-15   Fort Lauderdale, FL
   Advancing with Rails    January 19-22   Fort Lauderdale, FL *
   * Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!