On Tue, Nov 6, 2012 at 5:29 PM, Jermaine O. <[email protected]> wrote:
> > The same thing can be achieved with Enumerable#inject, which is the
> > generalization of this kind of "sum up the elements of a collection":
>
> Just what I need. Many thanks for this, works great. Appreciate it!
>
I'd rather use Set here since apparently entries must be present only once:
require 'set'
merged = Hash.new {|h,k| h[k] = Set.new}
hashes.each do |hash|
hash.each {|k, v| merged[k].merge(v)}
end
Cheers
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en