Skip to content

Instantly share code, notes, and snippets.

@etozzato
Created December 16, 2010 00:25
Show Gist options
  • Select an option

  • Save etozzato/742830 to your computer and use it in GitHub Desktop.

Select an option

Save etozzato/742830 to your computer and use it in GitHub Desktop.
ActiveRecord Extension
class ActiveRecord::Base
def self.hash_all(hash_key, *args)
hash = {}
collection = find(:all, *args)
unless collection.empty?
collection.each_with_index {|el, idx| hash[el.send(hash_key) || idx] = el}
end
hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment