aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/enumerable.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-01 17:37:34 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-01 17:37:34 -0700
commit61e8b23fe599ac54382251b44d9690f08a759fe1 (patch)
tree3c8b2f612a909aed51f08cf20d6679a166ded1b9 /activesupport/lib/active_support/core_ext/enumerable.rb
parentff2fdcc52b391514cb62c2a1ef29827ac94914c6 (diff)
downloadrails-61e8b23fe599ac54382251b44d9690f08a759fe1.tar.gz
rails-61e8b23fe599ac54382251b44d9690f08a759fe1.tar.bz2
rails-61e8b23fe599ac54382251b44d9690f08a759fe1.zip
speed up index_by by removing a lolinject
Diffstat (limited to 'activesupport/lib/active_support/core_ext/enumerable.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb5
1 files changed, 1 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index f1103029c8..6ecedc26ef 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -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.