rdoc update.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1eca24b1a5
commit
73fc3b5a34
19
enum.c
19
enum.c
@ -2418,15 +2418,18 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv)
|
|||||||
*
|
*
|
||||||
* If the block needs to maintain state over multiple elements,
|
* If the block needs to maintain state over multiple elements,
|
||||||
* local variables can be used.
|
* 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]
|
* a = [0,2,3,4,6,7,9]
|
||||||
* n = 0
|
* prev = a[0]
|
||||||
* p a.slice_before {|elt|
|
* p a.slice_before {|e|
|
||||||
* prev, n = n, elt
|
* prev, prev2 = e, prev
|
||||||
* prev > elt
|
* prev2 + 1 != e
|
||||||
* }.to_a
|
* }.map {|es|
|
||||||
* #=> [[3], [1, 4], [1, 5, 9], [2, 6], [5], [3, 5]]
|
* 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
|
* However local variables are not appropriate to maintain state
|
||||||
* if the result enumerator is used twice or more.
|
* if the result enumerator is used twice or more.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user