[DOC] Tweaks for Array#cycle (#11459)
This commit is contained in:
parent
2fbaff5351
commit
0228cf74e3
Notes:
git
2024-08-27 16:59:51 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>
24
array.c
24
array.c
@ -6784,13 +6784,16 @@ rb_ary_cycle_size(VALUE self, VALUE args, VALUE eobj)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* array.cycle {|element| ... } -> nil
|
* cycle(count = nil) {|element| ... } -> nil
|
||||||
* array.cycle(count) {|element| ... } -> nil
|
* cycle(count = nil) -> new_enumerator
|
||||||
* array.cycle -> new_enumerator
|
|
||||||
* array.cycle(count) -> new_enumerator
|
|
||||||
*
|
*
|
||||||
* When called with positive Integer argument +count+ and a block,
|
* With a block given, may call the block, depending on the value of argument +count+;
|
||||||
* calls the block with each element, then does so again,
|
* +count+ must be an
|
||||||
|
* {integer-convertible object}[rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects],
|
||||||
|
* or +nil+.
|
||||||
|
*
|
||||||
|
* If +count+ is positive,
|
||||||
|
* calls the block with each element, then does so repeatedly,
|
||||||
* until it has done so +count+ times; returns +nil+:
|
* until it has done so +count+ times; returns +nil+:
|
||||||
*
|
*
|
||||||
* output = []
|
* output = []
|
||||||
@ -6802,18 +6805,13 @@ rb_ary_cycle_size(VALUE self, VALUE args, VALUE eobj)
|
|||||||
* [0, 1].cycle(0) {|element| fail 'Cannot happen' } # => nil
|
* [0, 1].cycle(0) {|element| fail 'Cannot happen' } # => nil
|
||||||
* [0, 1].cycle(-1) {|element| fail 'Cannot happen' } # => nil
|
* [0, 1].cycle(-1) {|element| fail 'Cannot happen' } # => nil
|
||||||
*
|
*
|
||||||
* When a block is given, and argument is omitted or +nil+, cycles forever:
|
* If +count+ is +nil+, cycles forever:
|
||||||
*
|
*
|
||||||
* # Prints 0 and 1 forever.
|
* # Prints 0 and 1 forever.
|
||||||
* [0, 1].cycle {|element| puts element }
|
* [0, 1].cycle {|element| puts element }
|
||||||
* [0, 1].cycle(nil) {|element| puts element }
|
* [0, 1].cycle(nil) {|element| puts element }
|
||||||
*
|
*
|
||||||
* When no block is given, returns a new Enumerator:
|
* With no block given, returns a new Enumerator.
|
||||||
*
|
|
||||||
* [0, 1].cycle(2) # => #<Enumerator: [0, 1]:cycle(2)>
|
|
||||||
* [0, 1].cycle # => # => #<Enumerator: [0, 1]:cycle>
|
|
||||||
* [0, 1].cycle.first(5) # => [0, 1, 0, 1, 0]
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
|
rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user