From: johan556@... Date: 2007-03-21T08:32:37+09:00 Subject: Re: does Ruby not support multiple "initialize" methods for a class??? 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. /Johan Holmberg #------------------------------- class Point def self.create_cartesian(x,y) allocate.instance_eval do @x = x @y = y self end end def self.create_polar(length,angle) allocate.instance_eval do @x = length * Math.cos(angle) @y = length * Math.sin(angle) self end end end #-------------------------------