From: Patrick May Date: 2004-06-28T05:44:16+09:00 Subject: Re: Is it considered Harmful? I think that #become and #class= are _theoretically_ wrong. Such a method makes handling object life cycle ugly. Objects expect to be initialized first, they expect to have various pieces of state setup in a predictable manner. If an object of one class #become's another class, then the new class's methods can't count on having the proper state. Core dumps is what you get when this happens in c, but you'll have similar problems with 100% *.rb code. Edge cases not being handled correctly, missing instance variables, etc. To get around these errors, you end up needing an extra initialize function. This extra initialize always takes one argument, the object that is becoming the class. Tracking this extra lifecycle per class sounds like a recipe for bugs. To safely support this code: a = SomeClass.new a.become( AnotherClass ) I end up needing this code in AnotherClass: def update_instance_for_changed_class( old_instance ) case old_instance.class when SomeClass self.initialize( old_instance.attribute1, old_instance.attribute2 ) when .... .... end end Other than being uglier, I don't see how #become is different from: a = SomeClass.new a = AnotherClass.new( a.attribute1, a.attribute2 ) This example gets the mapping of SomeClass to AnotherClass out of AnotherClass and into the code that wants to map the two together. And my variable has effectively "become" a new class. Is the problem that you want to add methods? Then use Modules. Is the problem that you want to update all references to the new a? For one, #replace_self raises different issues than #become. Still, I have a hunch that for most uses of #replace_self there is a way to use of accessor methods instead. So, to sum up my ivory tower critique of #become and #class= * #become creates a duplicate lifecycle for objects, resulting in lots of complication * It doesn't really add that much functionality Cheers, Patrick p.s. Thanks for raising an interesting issue! I enjoyed following the conversation and thinking about the implications of #become / #class=