Any problem with the  marshal dump and load aproach of Chad Perrin?

Look...

arr =3D [{:fruit =3D> {:kind =3D> 'apple'}}, {:fruit =3D> {:kind =3D> 'bana=
na'}}]

Marshal.load(Marshal.dump arr).each do |h|
  h[:fruit][:kind] =3D 'coconut'
end

If it's ugly, you can try to beautify it...

class Object
  def deep_copy
    Marshal.load(Marshal.dump self)
  end
end

arr.deep_copy.each do |h|
  h[:fruit][:kind] =3D 'coconut'
end

Abinoam Jr.

On Tue, May 3, 2011 at 10:08 PM, John Feminella <johnf / bitsbuilder.com> wro=
te:
> Your example doesn't contain nested hashes, while mine does. That's
> what I was demonstrating -- it's a shallow copy, not a deep one.
>
> ~ jf
> --
> John Feminella
> Principal Consultant, BitsBuilder
> LI: http://www.linkedin.com/in/johnxf
> SO: http://stackoverflow.com/users/75170/
>
>
>
> On Tue, May 3, 2011 at 22:00, 7stud -- <bbxx789_05ss / yahoo.com> wrote:
>> John Feminella wrote in post #996498:
>>> On Tue, May 3, 2011 at 20:34, 7stud -- <bbxx789_05ss / yahoo.com> wrote:
>>>> Peter Hicks wrote in post #996483:
>>>>>
>>>>> What is the magic I am missing?
>>>>>
>>>>
>>>> clone():
>>>
>>> `clone` doesn't cut it, since it's creating shallow copies. An
>>> illustration of the problem:
>>>
>>
>> Really? =A0Look at my output. =A0It cuts it just fine.
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
>
>