1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

speed up index_by by removing a lolinject

This commit is contained in:
Aaron Patterson 2010-10-01 17:37:34 -07:00
parent ff2fdcc52b
commit 61e8b23fe5

View file

@ -90,10 +90,7 @@ module Enumerable
# => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
#
def index_by
inject({}) do |accum, elem|
accum[yield(elem)] = elem
accum
end
Hash[map { |elem| [yield(elem), elem] }]
end
# Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1.