Skip to content

Commit

Permalink
rdoc update.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed Mar 12, 2010
1 parent 1eca24b commit 73fc3b5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -2418,15 +2418,18 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv)
*
* 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.
*
* 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]]
* For example, three or more consecutive increasing numbers can be squashed
* as follows:
*
* 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.
Expand Down

0 comments on commit 73fc3b5

Please sign in to comment.