From: harryo@... (Harry Ohlsen) Date: 2002-04-02T09:10:56+09:00 Subject: Re: Creating an instance of a class without calling initialize() "Rich Kilmer" wrote in message > You actually may want to recommend that he use: > > obj = new > > FOR EACH ATTRIBUTE > obj.instance_eval "@#{attributeName}=#{attributeValue}" > END > > That way it works for attributes that do not have writer methods but > only reader methods (ie. Foo.x but not Foo.x=) Unfortunately, that won't work very well if the attribute value is an instance of an arbitrarily complex class, since what it's effectively trying to do is de-serialise/re-serialise atrributeValue as text :-). What I did, instead, was have it generate a setter on the fly, with a completely different name (ie, something like "__set_x__", rather than "x="), to avoid screwing up any setter that might exist. The thing about that is you can do the assignment via a send to the method, without having to convert the value to text, which you're forced to do if you try to do it as a single eval. Now that I think about it, though, I should probably handle that the same way as the new_without_init ... ie, alias x=, call it, then re-alias it (obviously, also catching the case where it doesn't exist and hence shouldn't after the assignment has been achieved).