You'll go round in circles!
This method of Enumerable
allows it to be repeated a defined number of times.
It can be used :
- with a block to iterate directly
- without a block, to obtain an
Enumerator
. - without parameters to repeat indefinitely
The infinite Enumerator
is perfect for alternating colors, for example.
With Ruby’s flexibility, we wanted to test a partial cycle, but the value is truncated!
Link to Ruby documentation for cycle
.