Array#assoc_to_h
This is one of those methods that really should be in the Ruby core library already.
Array#assoc_to_h
transforms an associative array to a hash map.
x = { :foo => "bar" }
y = x.map { |k, v| [k, v * 2] }
y # => [ [ :foo, "barbar" ] ]
y.assoc_to_h # => { :foo => "barbar" }
class Array
def assoc_to_h
result = {}
each do |key, value|
result[key] = value
end
return result
end
end