From: Robert Dober Date: 2007-03-13T16:36:12+09:00 Subject: Re: non-destructive merging of hashes in array On 3/13/07, Harrison Reiser wrote: > On Mar 12, 8:39 pm, "Mushfeq Khan" wrote: > > You can even do: > > > > hashes.inject(Hash.new {|h, k| 0}) {|result, hash| result.merge(hash) {|k, > > e, v| e + v}} > > Oh, you beat me to it. I might add, though, that the parameters in > the initializer block can be safely removed: > > hashes.inject(Hash.new {0}) {|memo, hash| memo.merge(hash) {|k,e,v| e > + v}} > > Harrison Reiser > and my humble contribution gives: hashes.inject{|memo, hash| memo.merge(hash) {|k,e,v| e+ v}} which is - as Gilles guessed correctly - a concise oneliner, boy I love Ruby. Robert -- We have not succeeded in answering all of our questions. In fact, in some ways, we are more confused than ever. But we feel we are confused on a higher level and about more important things. -Anonymous