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
a shortest one?
# 'Region' is a sample class here # you can put 'self.to_hash' method into any class you like class Region < ActiveRecord::Base def self.to_hash Hash[*all.map{ |x| [x.id, x] }.flatten] end end