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
This commit is contained in:
Marcel Molina 2006-03-01 21:12:18 +00:00
parent 1fdf578c17
commit 0d92ce59ff

@ -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