Skip to content

Instantly share code, notes, and snippets.

@bmarini
Created August 2, 2008 19:53
Show Gist options
  • Save bmarini/3770 to your computer and use it in GitHub Desktop.
Save bmarini/3770 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment