From: Sean O'Dell Date: 2004-06-29T03:04:21+09:00 Subject: Re: Is it considered Harmful? On Monday 28 June 2004 10:14, Hal Fulton wrote: > Sean O'Dell wrote: > >>With just #become (no class=), you can't create objects whose > >>#initialize is not called. It's just like swapping variables, except > >>all variables that point to the pointee are affected. > > > > You can't do that with #class= either. You can only call #class= on > > objects that exist, hence they've been initialized. The new class might > > not know what to do with the object, but the object certainly has already > > been initialized. > > You're missing his point. > > If I call Array.new, I certainly get an array whose #initialize > has been called. > > But if I then do arr.class = Net::HTTP, then Net:HTTP#initialize > does NOT get called (e.g., to set the host name or whatever). Ah...I see why I haven't connected with that issue now. I think of this as a "buyer beware" issue. If you change an existing object's class, be sure you change it to something that understands the object it is receiving. I think even #become would have these problems. Even using include could introduce methods to a class which didn't initialize instance data the way it expects. Sean O'Dell