On 11/17/05, J. Merrill <jvm_cop / spamcop.net> wrote:
> halostatue wrote:
>> On 11/16/05, Eric Mahurin <eric.mahurin / gmail.com> wrote:
>>> object into a strange state.
>> Obviously, I wasn't clear. I said "At a simplistic level, this is:"
>> ... This means that this is *essentially* what the operation would
>> do, but not necessarily the full scope of what would be needed. A
>> more "safe" operation would be:
>>
>>   class Object
>>     def replace(other)
>>       unless other.class == self.class
>>         raise TypeError,
>>           "cannot convert #{self.class} into #{other.class}"
>>       end
>>       other.instance_variables.each do |name|
>>         instance_variable_set(name,
>>             other.instance_variable_get(name))
>>       end
>>     end
>>   end
>>
>> This is, by the way, exactly what:
>>
>>   a = {}
>>   b = []
>>   b.replace a
>>
>> does. [snip]
>
> What if the receiver of #replace has instance variables that don't
> exist in the parameter? Do you intend for them to go away? If they
> don't, you could break code that uses
>     if @instancevar ...
>
> Doing so would require getting both sets of instance variables etc...

That's easier than one might think. I already do a lot of this work in
Transaction::Simple.

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