Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Array To Hash In Ruby

DZone's Guide to

Array To Hash In Ruby

·
Free Resource
Inspired by something Ryan Carver was trying to do:

a = [1, 2, 3]
Hash[*a.collect { |v|
    [v, v*2]
}.flatten]

It's not as foolproof as his solution, however!
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}