I want to merge array of hashes by prioritizing non-nil values.
I wrote like this:
hs = [{a: 1, b:2, c: nil},{a: nil, b:nil, c:3},{d: nil, e: 5}]
hs.reduce{|v1,v2| v1.merge(v2){|k,old,new| old || new} }
# => {:a=>1, :b=>2, :c=>3, :d=>nil, :e=>5}
Is there better way to implement this function?