goodieboy
2/15/2008 3:57:00 PM
Thanks. But the only problem with that is, the overriding hash will
completely destroy *all* of the values in the original. So if I want
to just override one value, I get only one value. In this example,
"Sam" is lost:
first = {
:data=>{
:name=>{
:first=>'Sam',
:middle=>'I',
:last=>'am'
}
}
}
second={
:data=>{
:name=>{
:middle=>'you',
:last=>'are'
}
}
}
all_new = first.merge(second)
puts all_new.inspect
On Feb 15, 10:47 am, "Farrel Lifson" <farrel.lif...@gmail.com> wrote:
> On 15/02/2008, goodieboy <goodie...@gmail.com> wrote:
>
> > Hi,
>
> > Does anyone know of a good recursive merge method for Hashes? I'd like
> > to be able to do something like:
>
> > new_h = first.merge_r(second).merge_r(third)
>
> > ... everything would be a copy, and hashes applied later in the
> > sequence override the previous finally, returning a completely new
> > hash... is there something out there like this?
>
> new_h = first.merge(second).merge(third)
>
> Farrel