Skip to content

Instantly share code, notes, and snippets.

class Array
# Converts [[k1,v1],[k2,v2]] into {k1 => v1, k2 => v2}
# The opposite of Hash#to_a
# Same as `Hash[ary.flatten]`
def to_h
inject({}) {|h,el| h[el[0]] = el[1]; h }
end
end