From: Pierre Lecocq Date: 2010-01-28T00:58:10+09:00 Subject: Re: Class with Multi Constrcutor ( initialize ) Hello Mido, There are several solutions to this problem. The first one is this equivalent of vaargs in C language def initialize(*args) args.each do |a| puts a.class.inspect end end The second one is to pass a hash or an array in parameter. And the third is to put default values to your args: def initialize(var1='', var2=0, var3=nil) end Hope i helped ! Kind regards Mido Peace wrote: > Hey .. > I'm Tryin' to port Some Java Module into Ruby , but I have a small > probleme , > how can I do to declare multi 'initialize Method' depending of the > number of user > argument > > i.e in Java we can have a Class with many constructor > class myClass { > > //... > public MyClass () { ... } // Defualt One > public MyClass (Object obj1 ) { ... } > public myClass ( Object obj1,Object obj2 ...,Object objn) { ... } > // ... > } > > I tried : > class myClass > def initialize () > // ... > end > > def intialize ( value ) > // ... > end > end > > but doesnt works ! > > I just wanna find a way to call the right constructor ( or initializer) > depending of the number of arguments > > > Thx ;) -- Posted via http://www.ruby-forum.com/.