aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/guides/source/active_support_overview.textile14
1 files changed, 13 insertions, 1 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile
index 352feb96fb..ac326d5a24 100644
--- a/railties/guides/source/active_support_overview.textile
+++ b/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:
+
+<ruby>
+entries_by_surname_initial = address_book.group_by do |entry|
+ entry.surname[0, 1].upcase
+end
+</ruby>
+
+WARNING. Active Support redefines +group_by+ in Ruby 1.8.7 so that it still returns an ordered hash.
h3. Extensions to +Array+