ruby-changes:15017
From: akr <ko1@a...>
Date: Fri, 12 Mar 2010 23:01:03 +0900 (JST)
Subject: [ruby-changes:15017] Ruby:r26892 (trunk): rdoc update.
akr 2010-03-12 23:00:49 +0900 (Fri, 12 Mar 2010) New Revision: 26892 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26892 Log: rdoc update. Modified files: trunk/enum.c Index: enum.c =================================================================== --- enum.c (revision 26891) +++ enum.c (revision 26892) @@ -2418,15 +2418,18 @@ * * If the block needs to maintain state over multiple elements, * local variables can be used. - * For example, monotonically increasing elements can be chunked as follows. + * For example, three or more consecutive increasing numbers can be squashed + * as follows: * - * a = [3,1,4,1,5,9,2,6,5,3,5] - * n = 0 - * p a.slice_before {|elt| - * prev, n = n, elt - * prev > elt - * }.to_a - * #=> [[3], [1, 4], [1, 5, 9], [2, 6], [5], [3, 5]] + * a = [0,2,3,4,6,7,9] + * prev = a[0] + * p a.slice_before {|e| + * prev, prev2 = e, prev + * prev2 + 1 != e + * }.map {|es| + * es.length <= 2 ? es.join(",") : "#{es.first}-#{es.last}" + * }.join(",") + * #=> "0,2-4,6,7,9" * * However local variables are not appropriate to maintain state * if the result enumerator is used twice or more. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/