Mark Hubbart
1/31/2005 5:01:00 AM
Hi,
On Mon, 31 Jan 2005 13:49:43 +0900, Jeff Davis <jdavis-list@empires.org> wrote:
> If MyClass.new calls the initialize method, what calls the new method?
> What if both are defined?
*You* call the new method. It's pre-defined in Class to work something
like this:
class Class
def new
obj = self.allocate # allocates the object
obj.initialize # calls the object's initialize method
return obj # returns the object
end
end
You can redefine new to do anything you want, remembering that people
will expect it to return an object of that class.
cheers,
Mark