Convert an array to a hash
1 2 class Array 3 def to_h 4 Hash[*self] 5 end 6 end
Use it like this:
1 2 ['action', 'go', 'id', 6].to_h # => { 'action' => 'go', 'id' => 6 }
DZone Snippets > danger > hash
13459 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
Danger http://6brand.com
1 2 class Array 3 def to_h 4 Hash[*self] 5 end 6 end
1 2 ['action', 'go', 'id', 6].to_h # => { 'action' => 'go', 'id' => 6 }