From: "Ara.T.Howard" Date: 2005-11-17T03:15:28+09:00 Subject: Re: Proposed RCR: Object#replace On Thu, 17 Nov 2005, Austin Ziegler wrote: > On the Sydney list, Daniel Berger has been asking about a generic > Object#replace call to work similarly to Hash#replace, String#replace, > and Array#replace. I see no reason that this could not be implemented > for all objects. At a simplistic level, this is: > > class Object > def replace(other) > other.instance_variables.each do |name| > instance_variable_set(name, other.instance_variable_get(name)) > end > end > end class SpecialFile < ::File end a = SpecialFile::new '4.txt', 'w' b = SpecialFile::new '2.txt', 'w' b.replace a a.close b << 42 # exception! i see where you are coming from, but wouldn't this more accurately be called something like Object#refer since all instance vars will then be shared? regards. -a -- =============================================================================== | ara [dot] t [dot] howard [at] gmail [dot] com | all happiness comes from the desire for others to be happy. all misery | comes from the desire for oneself to be happy. | -- bodhicaryavatara ===============================================================================