From: Robert Klemme Date: 2003-11-24T17:17:11+09:00 Subject: Re: Destructive type conversion (to_i!, to_f!) "David A. Black" schrieb im Newsbeitrag news:Pine.LNX.4.44.0311221639400.10991-100000@wobblini.net... [snip] > I think the best way to look at the way it's all designed is: an > object is spawned, and has certain immutable characteristics that make > it that object, and which bootstrap it into object-space: > specifically, its class and its object id. Neither of these things > can change; there's no such thing as being un- or re-spawned (which is > fine, since there's always a supply of new objects), and by definition > an object which has a different id is a different object. > > Once spawned and bootstrapped, the object has a lot of freedom. It > can be extended, unextended, respond this way and that to an arbitrary > number of methods, for arbitrary durations, and so on. But it's still > itself; that is, all of this freedom (which is basically freedom of > type) takes place within the bootstrapping process I've described. [snip] > You might be interested to look through the archives for discussion of > the idea of "become", which is probably the closest thing to what > you're describing among things that have been kicked around on the > list. I think, though, that it tends to come up against both the > question of what it would mean, given Ruby's design, and the question > of whether it would really add anything (which might depend on what it > would mean :-) And there's always the workaround of an instance holding a reference to another instance that is exchanged: class Ref def initialize(obj=nil); replace(obj); end def get; @obj; end def replace(obj); @obj = obj; end def clear; replace(nil); end end .... or probably a more sophisticated version using Delegator or SimpleDelegator. As long as you only refer instances of Ref, the type of the referenced instance can change arbitrarily. Regards robert