Method: Enumerable#each_cons

Defined in:
enumerator.c

#each_cons(n) { ... } ⇒ Object #each_cons(n) ⇒ Object

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]

Overloads:

  • #each_cons(n) { ... } ⇒ Object

    Yields:



194
195
196
# File 'enumerator.c', line 194

static VALUE
enum_each_cons(obj, n)
VALUE obj, n;