When a range is used as an iterator, each value in the sequence is returned. : As Iterator « Range « Ruby






When a range is used as an iterator, each value in the sequence is returned.


# So you can use a range to do things like create an array of digits:

(1..9).to_a # => [1, 2, 3, 4, 5, 6, 7, 8, 9]

 








Related examples in the same category

1.each and each_with_index loop with range
2.each_slice loop with range
3.each_cons loop with range