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

Ticket #4427 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 3 years ago

[PATCH] Allow Enumerable#group_by to handle arrays

Reported by: andy@tinnedfruit.org Assigned to: David
Priority: normal Milestone:
Component: ActiveSupport Version:
Severity: normal Keywords: enumerable group_by array
Cc:

Description

This patch allows for group_by to take arrays. Example:

!#ruby
Event = Struct.new(:title, :occurs_on)
events = [ Event.new("Cooking",["Mon","Tue"]), Event.new("Skiing","Mon") ]

events.group_by { |event| event.occurs_on }

{"Mon"=>
        [#<struct Event title="Cooking", occurs_on=["Mon", "Tue"]>,
         #<struct Event title="Skiing", occurs_on="Mon">],
 "Tue"=>[#<struct Event title="Cooking", occurs_on=["Mon", "Tue"]>]}

Attachments

group_by_array.patch (1.7 kB) - added by andy@tinnedfruit.org on 03/26/06 23:06:18.

Change History

03/26/06 23:06:18 changed by andy@tinnedfruit.org

  • attachment group_by_array.patch added.

03/27/06 05:12:42 changed by marcel

  • status changed from new to closed.
  • resolution set to wontfix.

Ruby 1.9 includes a built in Enumberable#group_by. We want to stay compatible with that.