From: Gary Wright Date: 2007-03-04T09:40:12+09:00 Subject: Re: Duck Typing Hash-Like Objects On Mar 3, 2007, at 1:02 PM, Ed Howland wrote: > This may be OT, (or merely off-base,) but somewhere else on this list > I read about using mutators (not sure if that is the formal name or > not) on #new. This keeps the complexity out of initialize having to > parse each argument for its type. > > E.g. > > my_obj = MyClass.new # no arg ctor > my_obj = MyClass.new('John', 'Smith') # canon - takes strings > my_obj = MyClass.new.from_hash {:last_name => > 'Smith', :first_name => 'John'} > my_obj = MyClass.new.from_arr ['John', 'Smith'] This certainly simplifies MyClass#initialize but Ruby is flexible enough that you can create your own methods to allocate and initialize without going through MyClass#initialize: class MyClass class <