I'd say the refactor is barely readable, the first version is better. Anyway, if you use functional abstractions instead of doing a imperative processing from scratch, algorithms are more clear. In this case, it's a pity Ruby hasn't got [Enumerable#map_by][1] (a `group_by` variation where you can control what to accumulate), then you could write: require 'facets' class Array def merge_hashes flat_map(&:to_a).map_by { |k, v| [k, v] } end end Note that this always return an array as value, instead of the scalar/list you have. Having mixed types in data structures is usually a bad idea: every time you have to work with a value, you need to check whether it's an array or not, not nice. [1]: http://www.rubydoc.info/github/rubyworks/facets/Enumerable#map_by-instance_method