From: Austin Ziegler Date: 2003-06-12T05:35:18+09:00 Subject: Re: Multiple Initialize methods? On Thu, 12 Jun 2003 04:54:59 +0900, Nick wrote: > Hi, > > I need to create a class either with a param in the construction > or nothing: > > something = Object.new > or > something = Object.new(val1, val2) > > I have created an emtpy initialize() method and one with the two > params. If I try to create the object with nothing (first version) > then I get "ArgumentError: wrong number of arguments(0 for 2)". > > class Something > def initialize() > end > def initialize(xdim, ydim) > @xdim = xdim > @ydim = ydim > end > > I put the empty initialze in when things didnt work, thinking i > needed at least a marker. Ruby isn't C++; there is no overloading in that way. What you want is perhaps: class Something def initialize(xdim = nil, ydim = nil) @xdim = xdim || 0 @ydim = ydim || 0 end end You can also use *args. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.06.11 * 16:32:43