I seem to run into this very often. I need to build a Hash from an array using an attribute of each object in the array as the key.
Lets say I need a hash of example us
In case someone got plain array
arr = ["banana", "apple"] Hash[arr.map.with_index.to_a] => {"banana"=>0, "apple"=>1}