Method: Array#to_h_multi

Defined in:
lib/core/facets/to_hash.rb

#to_h_multiObject

When a mixed or multi-element accociative array is used, the result is as follows:

a = [ [:a,1,2], [:b,2], [:c], :d ]
a.to_h  #=> { :a=>[1,2], :b=>[2], :c=>[], :d=>[] }

If the first entry of the subelements is the same, then the values will be merged using #concat.

a = [ [:a,1,2], [:a,3], [:a,4], [:a], :a ]
a.to_h_multi  #=> { :a=>[1,2,3,4] }


177
178
179
180
181
182
183
184
# File 'lib/core/facets/to_hash.rb', line 177

def to_h_multi
  h = {}
  each do |k,*v| 
    h[k] ||= []
    h[k].concat(v)
  end
  h
end