From: Florian Gross Date: 2004-06-26T04:28:06+09:00 Subject: Re: Is it considered Harmful? Jim Weirich wrote: > Florian Gross said: >> [problems with proxies] > Comparisons are problematic because the first line of a comparison is > often "Are you the same class as me?". Proxies arent't the right class so > the comparisons fail. It depends -- the answer to that question can be overloaded in most cases. (Though Object.instance_method(:class).bind(obj).call will always give you the real class and I think that some of the internal methods actually do something like that.) > Actually, rather than a become or class= method, I would be interested in > a swap_identitys method. For example, to make a proxy object real ... > > def make_real > obj = read_real_object_from_the_database > swap_identities(self, obj) > end > > When identities are swapped, every reference in the system to the first > object will magically become a reference to the second object, and > vice-versa. This is how Squeak implements this AFAIK -- it just iterates through all Object references and changes them. I'm not sure, but this could be a bit slow, maybe. (And I'm not sure if it would be a general solution for the problems with Proxy objects -- it would work in the lazy database example, but there might be other problematic use cases.) Regards, Florian Gross