From: Austin Ziegler Date: 2004-06-29T01:27:05+09:00 Subject: Re: Is it considered Harmful? 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" It should be utterly obvious to anyone smarter than George Bush that this simply won't work. Tempfile must be properly initialized using Tempfile#new, and simply saying that foo is now a Tempfile doesn't actually initialize those things upon which Tempfiles methods rely. Yes, foo is initialized, but it's not a properly initialized Tempfile even though you've called it one. Pathological case? You bet. But simply doing #class= doesn't do the proper initialization. #become (or #swap, if you prefer) is far more useful and practical, but only in cases of type refinement (and I'm dubious on the value of that) or proxy replacement (and I'm enthusiastic about the value of that). I really don't think that the danger of either one of them is worth the limited value that it represents given that smart programming can get around the problem in both cases. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca