diff options
author | Marcel Molina <marcel@vernix.org> | 2006-03-01 21:12:18 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2006-03-01 21:12:18 +0000 |
commit | 0d92ce59ff45a0e2091c89e5ab976bff803f4b22 (patch) | |
tree | 312d1c4ba7afc296f9fd20bb867567bc19cc8c45 /activesupport | |
parent | 1fdf578c17b38fc5391996d2016f4170bc3bf5ba (diff) | |
download | rails-0d92ce59ff45a0e2091c89e5ab976bff803f4b22.tar.gz rails-0d92ce59ff45a0e2091c89e5ab976bff803f4b22.tar.bz2 rails-0d92ce59ff45a0e2091c89e5ab976bff803f4b22.zip |
Make Enumerable#group_by return a Hash (sacrificing the preservation of ordering) so that it is more compatible with the version that is in Ruby 1.9
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3727 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 11 |
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 |