each_cons loop with range : As Iterator « Range « Ruby






each_cons loop with range


(1..5).each_cons(3) {|x| print x }    # Prints "[1,2,3][2,3,4][3,4,5]"

 

Related examples in the same category

1.When a range is used as an iterator, each value in the sequence is returned.
2.each and each_with_index loop with range
3.each_slice loop with range