Convert Array to Hash
require "enumerator" class Array def to_h Hash[*enum_with_index.to_a.flatten] end end %w{a b c d}.to_h # => {"a"=>0, "b"=>1, "c"=>2, "d"=>3}
11453 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
require "enumerator" class Array def to_h Hash[*enum_with_index.to_a.flatten] end end %w{a b c d}.to_h # => {"a"=>0, "b"=>1, "c"=>2, "d"=>3}