method
each_cons
Ruby latest stable (v1_8_7_72)
-
1 note -
Class: Enumerable
each_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}
# 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]
Register or
log in
to add new notes.
yonosoytu -
August 23, 2008
0 thanks
Needs requiring 'enumerator' to work
This method needs that you
require 'enumerator'
for this method to be available.

