From: Austin Ziegler Date: 2005-02-22T07:08:44+09:00 Subject: Re: Constructor overloading??? On Tue, 22 Feb 2005 07:01:59 +0900, Panagiotis Karvounis wrote: > I am not trying sth special.I am testing language features that I > use with Java. > > I was trying to use initialize more than once (think Java-default > constructor, other with one argument etc...) > > Example with Java: > > public class Rectangle > { > public int a,b; > public Rectangle() > { > a=0; > b=0; > } > public Rectangle(int c,int d) > { > a=c; > b=d; > } > } > So I tried: > class Rectangle > def initialize > @a=0 > @b=0 > end > > def initialize(c,d) > @a=c > @b=d > end > end class Rectangle def initialize(a = 0, b = 0) @a = a @b = b end end That will work very well for you. You can do any number of other things like this that I find work as well or better than actual argument overloading, mostly because Ruby is dynamically typed. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca