On Wednesday, August 16, 2006, at 3:34 AM, Rick DeNatale wrote:
>On 8/14/06, Russell Fulton <r.fulton / auckland.ac.nz> wrote:
>
>>
>> I have printed out host and hosts[ "default-#{type}"]:
>>
>>
>> #<#<Class:0xb7537bc4>:0xb73e5a00>
>> #<#<Class:0xb7537bc4>:0xb73e599c>
>
>But those ARE two different instances.  The interesting thing is that
>the class in both cases seems to be anonymous.
>
>How did you build hosts?  You say that it contains different "class
>instances"
>
>One way to get such anonymous classes would be something like this:
>
>irb(main):040:0> fd = Foo.dup
>=> #<Class:0xb7d1404c>
>irb(main):041:0> fd.new
>=> #<#<Class:0xb7d1404c>:0xb7d11310>
>irb(main):042:0> fd.new
>=> #<#<Class:0xb7d1404c>:0xb7d0f074>
>irb(main):043:0> fd.new.equal?(fd.new)
>=> false
>
>Note that the two instances have the same oid for their class, (which
>is the copy of the Foo class), but different oids of their own.
>--
>Rick DeNatale
>
>IPMS/USA Region 12 Coordinator
>http://ipmsr12.denhaven2.com/
>
>Visit the Project Mercury Wiki Site
>http://www.mercuryspacecraft.com/
>

As I recently discovered, arrays don't get deep copied with dup or  
clone.  My guess is that ruby stores a pointer to an array internally  
and *that* is what gets copied when you clone the object.  So both  
copies point to the original array.

_Kevin
www.sciwerks.com

-- 
Posted with http://DevLists.com.  Sign up and save your mailbox.