method
each_cons
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
each_cons(p1)
public
Iterates the given block for each array of consecutive <n> elements. If no block is given, returns an enumerator.
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
![Default_avatar_30](https://www.gravatar.com/avatar/49b6123803e4f327144e991daab62f77?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank
Needs requiring 'enumerator' to work
This method needs that you
require 'enumerator'
for this method to be available.