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
You can add to_hash to Array yourself.
class Array def to_hash(&block) Hash[*self.map {|e| [block.call(e), e] }.flatten] end end ary = [collection of ActiveRecord objects] ary.to_hash do |element| element.id end