From: Austin Ziegler Date: 2004-06-29T02:19:35+09:00 Subject: Re: Is it considered Harmful? On Tue, 29 Jun 2004 01:48:26 +0900, Sean O'Dell wrote: > On Monday 28 June 2004 09:27, Austin Ziegler wrote: > > On Tue, 29 Jun 2004 00:58:22 +0900, Sean O'Dell wrote: > > > #class= can only be called on existing objects, so it can't prevent > > > initialization from happening (it already happened before you can even > > > make the call). The takeover class inherits an already-initialized > > > object. I'm not sure how else to say that. The object is already > > > initialized, #class= cannot prevent that. Both classes, the old and the > > > new, work with an already-initialized object. > > > > So ... with your modifications, I can safely do: > > > > foo = Object.new > > foo.class = Tempfile > > foo.write "bar" > > Safely, yes. Usefully, no. Tempfile can't do much with just an Object > instance, and since its methods expect its own data and nothing else, it > really would just complain that it can't do anything useful. No, it wouldn't work safely, and your protestations to the contrary won't change that -- Tempfile *expects* that by time you would call #write on an object of its class, the tempfile will be open. You have introduced a situation, with #class=, where not only is the tempfile not open, it simply does not exist. You also demonstrate a fundamental misunderstanding of the difference between #class= and #become; they are not related. foo = Object.new foo.class = Tempfile is not the same as: foo = Object.new foot = Tempfile.new("foot") foo.become(foot) All references to foo now become references to foot, and foo itself is released for garbage collection. It should really be quite obvious why one is safer than the other. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca