I want to combine an array of hashes with non-nil priorities.
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} }
Is there a better way to implement this feature?
source
share