On 11/16/05, David A. Black <dblack / wobblini.net> wrote:
> On Thu, 17 Nov 2005, Austin Ziegler wrote:
>> On 11/16/05, Eric Mahurin <eric.mahurin / gmail.com> wrote:
>>> On 11/16/05, Austin Ziegler <halostatue / gmail.com> wrote:
>>>> This is, by the way, exactly what:
>>>>   a = {}
>>>>   b = []
>>>>   b.replace a
> Did you mean b = {} ?

No. It was intentionally to throw an exception, just as my (more robust)
sample implementation did.

[...]
>> 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?

It's mostly the "having to do with state" umbrella. Consider:

  a = { :x => "a" }
  b = {}
  b.replace a
  b[:x].object_id == a[:x].object_id # true

I could certainly implement a generic #replace to be added with
Transaction::Simple; I would probably implement it to be similar to what
I have posted here. I do, however, think that there is a legitimate use
case for this being in the core and implemented either in C or in the
RubyC dialect of Ruby.

-austin
--
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca