Michael Sullivan <mps / blackbird.discomsys.com> writes:

> Hi,
>
> I have a module I would like to do some initialization of a class when a
> new instance is created.  What is the best way my initialization code
> executes when a new instance of the object or a sub-class of the object
> is instantiated?  I'd like this to be as transparent to the user as
> possible.
>
> Should I define a "new" method in my module and then do a super?
> Something like this:
>
> module Foo
> 	def new
> 		# do some stuff here....
> 		super
> 	end
> end

Yes, except that the function should be called "initialize".  Ruby
calls the "initialize" method on every object when it is created.


> What are the implications of this?  Is there a better way to have
> code execute upom instantiation of an object?  Even in a child
> object?

If the child object doesn't call "super" in its implementation of
"initialize" then the super class's "initialize" method won't be
called.

-- 
matt