From: "David A. Black" Date: 2005-11-17T11:15:06+09:00 Subject: Re: Proposed RCR: Object#replace Hi -- On Thu, 17 Nov 2005, Austin Ziegler wrote: > On 11/16/05, Eric Mahurin wrote: >> On 11/16/05, Austin Ziegler wrote: >>> This is, by the way, exactly what: >>> a = {} >>> b = [] >>> b.replace a Did you mean b = {} ? > I am suggesting that we implement the same sort of behaviour that we see > in Hash#replace. > >> But, it still doesn't seem very encapsulated because it is using >> instance_variable_get on other. > > It's the best way to do it. It's not perfect, actually, because it's > only getting instance variables that are currently in self. It would > need to possibly be a bit more robust (pure pseudocode here): > > class Object > def replace(other) > # check to make sure that we claim to be the same thing > # copy all instance variables from other > # delete instance variables in self that aren't in other > # return self > end > end I'm still totally not understanding what copying instance variables has to do with Hash/String/Array#replace operations. a = {} b = {} a.instance_eval { @x = 1 } b.replace(a) b.instance_eval { p @x } # nil Other than the big umbrella category of "having to do with state", what's the connection? David -- David A. Black dblack@wobblini.net