From: Daniel Berger Date: 2007-03-21T10:36:05+09:00 Subject: Re: does Ruby not support multiple "initialize" methods for a class??? Gregory Seidman wrote: > On Wed, Mar 21, 2007 at 10:09:36AM +0900, Chad Perrin wrote: >> On Wed, Mar 21, 2007 at 08:32:37AM +0900, johan556@gmail.com wrote: >>> On 3/20/07, Greg Hauptmann wrote: >>>> Hi, >>>> >>>> Q1 - Does Ruby not support multiple "initialize" methods for a class? >>>> >>>> Q2 - If no is there a reason for this out of curiosity? >>>> >>>> Q3 - What approach is recommended if this constraint does exist? >>>> >>> I have been using the following pattern to implement multiple >>> constructors for a class. It is only a variation of the already >>> proposed solutions, but by using "instance_eval" I could avoid having >>> to create separate new/initialize-like methods for each constructor. >> I've heard it said -- and I tend to agree -- that regular use of >> "patterns" is a sign that the language lacks something. I wonder if >> that is the case with Ruby, as applies to multiple constructor behavior >> implementation. >> >> I say "wonder" because I really am not certain in this case. > > Well, it's a choice. You can either have overloading or dynamic typing, but > not both. Not true. Perl 6 will have optional static typing [1]. Sydney faked it with a Behavior you could import (that used the parser to handle it, not a compile time step, IIRC). It's possible. The question is whether or not it's desirable. I vote yes, others say no, and still others are in favor of some sort of type inferencing. It's been brought up before - you can search the archives. :) Regards, Dan [1] http://www.perl.com/pub/a/2007/03/01/perl-6-parameter-passing.html