Browse files

AS guide: documents Enumerable#group_by

  • Loading branch information...
1 parent b4e11df commit e0d3cec3cc4c0e8baa2440202f9451a35b3ef9d5 @fxn fxn committed Sep 15, 2009
Showing with 13 additions and 1 deletion.
  1. +13 −1 railties/guides/source/active_support_overview.textile
@@ -788,7 +788,19 @@ h3. Extensions to +BigDecimal+
h3. Extensions to +Enumerable+
+h4. +group_by+
+Ruby 1.8.7 and up define +group_by+, and Active Support does it for previous versions.
+This iterator takes a block and builds an ordered hash with its return values as keys. Each key is mapped to the array of elements for which the block returned that value:
+entries_by_surname_initial = address_book.group_by do |entry|
+ entry.surname[0, 1].upcase
+WARNING. Active Support redefines +group_by+ in Ruby 1.8.7 so that it still returns an ordered hash.
h3. Extensions to +Array+

0 comments on commit e0d3cec

Please sign in to comment.