2 solutions have been presented.  I think the original poster's question was
sufficiently vague to make both of the solutions valid.

So, original poster: what were your intentions?  Did you need the only the
hashes in the array preserved, or did you ALSO need the contents of the
hashes in the array preserved?  If the former, then clone/dup is fine.  If
the latter, then you need some kind of deep copy.  The "simplest" deep copy
I can think of is the Marshal#dump/load one.

Saludos,
Doug

On Wed, May 4, 2011 at 1:50 PM, Chad Perrin <code / apotheon.net> wrote:

> On Thu, May 05, 2011 at 04:17:53AM +0900, Christopher Dicely wrote:
> >
> > The #clone based method presented upthread (which wasn't mine, it was
> > 7stud's) works perfectly for the data and requirements presented. It
> > doesn't work if, in addition to wanting to lose changes to the passed
> > hashes, one also wants to lose any changes resulting from manipulation
> > of the data in the hashes, but that wasn't requested.
>
> Are you seriously claiming that the person's statements seemed to you to
> indicate a desire for the data to change in the original data structure?
>
> Seriously?
>
>
> >
> > That is, since you work on a local copy of each hash, mutating methods
> > called on the hash won't have any lasting effect, but mutating methods
> > called on keys or values extracted from the (local copy of the) hash
> > will affect the objects stored in the original hash. Avoiding this kind
> > of effect was not requested.
>
> It really seemed implied from where I was sitting.
>
>
> >
> > Sure, but its way overkill for it. You only need deep copies if you
> > have requirements that weren't stated (avoiding effects from mutating
> > methods called not on the hashes being passed but on the keys or values
> > of the hashes.)
>
> I'm not sure why you're so pedantically splitting hairs when the actual
> intent seemed pretty obvious: no changes.
>
>
> > >
> > > 2. Is there some less-convoluted approach that works for the more
> > > complex needs you presented?
> >
> > I'm not sure what relevance this has.
>
> I think you're playing dumb.
>
> --
> Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
>