diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index f35c8f86c5..c3a351538f 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -15,8 +15,13 @@ module Enumerable # "2006-02-24 -> Transcript, Transcript" # "2006-02-23 -> Transcript" def group_by - inject({}) do |groups, element| - (groups[yield(element)] ||= []) << element + 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 groups end end if RUBY_VERSION < '1.9' |