From: Florian Gross Date: 2005-01-26T05:25:48+09:00 Subject: Re: Self and Ruby Comparisons Trans wrote: > Quite right, I'm not sure Ruby is particularly suited for role > swapping. (Prototype-based OOP handles it gracefully) And I don't know > how inefficent #become would be. It would be nice to think its just a > matter of changing one pointer, but I know that's not the case. It's still not too much work. Ignoring the checks that need to be done the basic task works like this: Create a copy of the object and swap the five fields of their internal structs -- after that invalidate the method cache and optionally migrate exivars and perhaps also the finalizer. I think you can safely assume that this overhead is constant.