aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-09-16 00:01:11 +0200
committerXavier Noria <fxn@hashref.com>2009-09-16 00:01:11 +0200
commite0d3cec3cc4c0e8baa2440202f9451a35b3ef9d5 (patch)
treebab653af4bdd52b3d42b6d65b06640e1d6f30ceb /railties
parentb4e11dfdac85bb089f256499cc3ffb6ec7672f8a (diff)
downloadrails-e0d3cec3cc4c0e8baa2440202f9451a35b3ef9d5.tar.gz
rails-e0d3cec3cc4c0e8baa2440202f9451a35b3ef9d5.tar.bz2
rails-e0d3cec3cc4c0e8baa2440202f9451a35b3ef9d5.zip
AS guide: documents Enumerable#group_by
Diffstat (limited to 'railties')
-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+