Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8516

Show
Ignore:
Timestamp:
12/31/07 21:30:17 (9 months ago)
Author:
david
Message:

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]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8505 r8516  
    11*SVN* 
     2 
     3* 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] 
    24 
    35* remove multiple enumerations from ActiveSupport::JSON#convert_json_to_yaml when dealing with date/time values.  [rick] 
  • trunk/activesupport/lib/active_support/core_ext/enumerable.rb

    r7474 r8516  
    1616  #   "2006-02-23 -> Transcript" 
    1717  def group_by 
    18     inject({}) do |groups, element| 
    19       (groups[yield(element)] ||= []) << element 
     18    inject([]) do |groups, element| 
     19      value = yield(element) 
     20      if (last_group = groups.last) && last_group.first == value 
     21        last_group.last << element 
     22      else 
     23        groups << [value, [element]] 
     24      end 
    2025      groups 
    2126    end