aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/enumerable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/enumerable.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb17
1 files changed, 2 insertions, 15 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index 35a8e0538c..c448d0454d 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -15,23 +15,10 @@ module Enumerable
# "2006-02-24 -> Transcript, Transcript"
# "2006-02-23 -> Transcript"
def group_by
- groups = []
-
- inject({}) do |grouped, element|
- index = yield(element)
-
- if group = grouped[index]
- group << element
- else
- group = [element]
- groups << [index, group]
- grouped[index] = group
- end
-
+ inject ActiveSupport::OrderedHash.new do |grouped, element|
+ (grouped[yield(element)] ||= []) << element
grouped
end
-
- groups
end if RUBY_VERSION < '1.9'
# Calculates a sum from the elements. Examples: