diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-23 07:25:20 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-23 07:25:20 +0000 |
commit | 8273280a637a5e40de2c37dd1da507c749b11aab (patch) | |
tree | 47f6a1cfceccd4811b45a8722a874ec60ad88088 /activesupport/lib | |
parent | fc71a07edb214a7f8c08ef69b6e6f4284761de5d (diff) | |
download | rails-8273280a637a5e40de2c37dd1da507c749b11aab.tar.gz rails-8273280a637a5e40de2c37dd1da507c749b11aab.tar.bz2 rails-8273280a637a5e40de2c37dd1da507c749b11aab.zip |
Enumerable#group_by uses ActiveSupport::OrderedHash
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8700 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/enumerable.rb | 17 |
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: |