Method: Array#to_h_assoc
- Defined in:
- lib/core/facets/to_hash.rb
#to_h_assoc ⇒ Object
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 any subelements are the same, then the value will be set to the last occuring value.
a = [ :x, [:x], [:x,1,2], [:x,3], [:x,4] ]
a.to_h_assoc #=> { :x=>[4] }
157 158 159 160 161 162 163 |
# File 'lib/core/facets/to_hash.rb', line 157 def to_h_assoc h = {} each do |k,*v| h[k] = v end h end |