Changed the implementation of Enumerable#group_by to use a double array approach instead of a hash such that the insert order is honored [DHH/Marcel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8516 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
07de7612bd
commit
438b108c6b
@ -1,5 +1,7 @@
|
|||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Changed the implementation of Enumerable#group_by to use a double array approach instead of a hash such that the insert order is honored [DHH/Marcel]
|
||||||
|
|
||||||
* remove multiple enumerations from ActiveSupport::JSON#convert_json_to_yaml when dealing with date/time values. [rick]
|
* remove multiple enumerations from ActiveSupport::JSON#convert_json_to_yaml when dealing with date/time values. [rick]
|
||||||
|
|
||||||
* Hash#symbolize_keys skips keys that can't be symbolized. #10500 [Brad Greenlee]
|
* Hash#symbolize_keys skips keys that can't be symbolized. #10500 [Brad Greenlee]
|
||||||
|
@ -15,8 +15,13 @@ module Enumerable
|
|||||||
# "2006-02-24 -> Transcript, Transcript"
|
# "2006-02-24 -> Transcript, Transcript"
|
||||||
# "2006-02-23 -> Transcript"
|
# "2006-02-23 -> Transcript"
|
||||||
def group_by
|
def group_by
|
||||||
inject({}) do |groups, element|
|
inject([]) do |groups, element|
|
||||||
(groups[yield(element)] ||= []) << element
|
value = yield(element)
|
||||||
|
if (last_group = groups.last) && last_group.first == value
|
||||||
|
last_group.last << element
|
||||||
|
else
|
||||||
|
groups << [value, [element]]
|
||||||
|
end
|
||||||
groups
|
groups
|
||||||
end
|
end
|
||||||
end if RUBY_VERSION < '1.9'
|
end if RUBY_VERSION < '1.9'
|
||||||
|
Loading…
Reference in New Issue
Block a user