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:
parent
ff2fdcc52b
commit
61e8b23fe5
1 changed files with 1 additions and 4 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue