Notes posted by dantealg
RSS feed
dantealg -
May 12, 2015
0 thanks
RE: Convert an Array of Arrays to a Hash using inject
Another way to convert an array of arrays to a hash using inject:
array = [['A', 'a'], ['B', 'b'], ['C', 'c']] hash = array.inject({}) do |memo, values| memo.merge!(values.first => values.last) end hash # => {'A' => 'a', 'B' => 'b', 'C' => 'c'}