aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb11
1 files changed, 3 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index 8a097dcd90..a49c4c701b 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -23,14 +23,9 @@ module Enumerable #:nodoc:
# "2006-02-24 -> Transcript, Transcript"
# "2006-02-23 -> Transcript"
def group_by
- inject([]) do |groups, element|
- value = yield(element)
- if (last_group = groups.last) && last_group.first == value
- last_group.last << element
- else
- groups << [value, [element]]
- end
+ inject({}) do |groups, element|
+ (groups[yield(element)] ||= []) << element
groups
end
- end
+ end
end