Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 0d92ce59ff45a0e2091c89e5ab976bff803f4b22 1 parent 1fdf578
Marcel Molina authored
Showing with 3 additions and 8 deletions.
  1. +3 −8 activesupport/lib/active_support/core_ext/enumerable.rb
View
11 activesupport/lib/active_support/core_ext/enumerable.rb
@@ -23,14 +23,9 @@ def first_match
# "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
Please sign in to comment.
Something went wrong with that request. Please try again.