From: Dan Doel Date: 2003-12-18T17:14:02+09:00 Subject: Re: Newbie questions Jim Frapper wrote: >- The ability to overload constructors. > > The way multiple constructors should probably be done in Ruby is similar to the way people do it in Smalltalk. For example, if you're modeling a mathematical plane in Smalltalk, you might define the following constructors: withPoint: p1 withPoint: p2 withPoint: p3 withPoint: p withNormalVector: n doing: plane <- Plane new Would just make a default plane with no instance variables set, while plane <- Plane withPoint: point1 withNormalVector: vector Would make a fully qualified plane. Analogues in Ruby would go something like: class Plane def Plane.fromPoints(p1, p2, p3) ... end def Plane.fromPointAndNormal(p, n) ... end end There's nothing special about #new that means it's the only thing you're allowed to call a constructor (or that you need to allow it to be a public constructor at all. In the above example, you'd probably want to make it private). All you need to do is possibly broaden your definition of constructor a bit. - Dan