Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v1_8_7_330) is shown here.
enum_cons(p1)
public
Iterates the given block for each array of consecutive <n> elements.
If no block is given, returns an enumerator.a
e.g.:
(1..10).each_cons(3) {|a| p a}
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, 6]
[5, 6, 7]
[6, 7, 8]
[7, 8, 9]
[8, 9, 10]
/*
* call-seq:
* each_cons(n) {...}
* each_cons(n)
*
* Iterates the given block for each array of consecutive <n>
* elements. If no block is given, returns an enumerator.a
*
* e.g.:
* (1..10).each_cons(3) {|a| p a}
* # outputs below
* [1, 2, 3]
* [2, 3, 4]
* [3, 4, 5]
* [4, 5, 6]
* [5, 6, 7]
* [6, 7, 8]
* [7, 8, 9]
* [8, 9, 10]
*
*/
static VALUE
enum_each_cons(obj, n)
VALUE obj, n;
{
long size = NUM2LONG(n);
VALUE args[2];
if (size <= 0) rb_raise(rb_eArgError, "invalid size");
RETURN_ENUMERATOR(obj, 1, &n);
args[0] = rb_ary_new2(size);
args[1] = (VALUE)size;
rb_block_call(obj, SYM2ID(sym_each), 0, 0, each_cons_i, (VALUE)args);
return Qnil;
}
1Note
This method needs that you
require 'enumerator'
for this method to be available.