From e0d3cec3cc4c0e8baa2440202f9451a35b3ef9d5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 16 Sep 2009 00:01:11 +0200 Subject: AS guide: documents Enumerable#group_by --- railties/guides/source/active_support_overview.textile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'railties') 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: + + +entries_by_surname_initial = address_book.group_by do |entry| + entry.surname[0, 1].upcase +end + + +WARNING. Active Support redefines +group_by+ in Ruby 1.8.7 so that it still returns an ordered hash. h3. Extensions to +Array+ -- cgit v1.2.3