enum.cycle(n=nil) { |obj| block } â nil
enum.cycle(n=nil) â an_enumerator
enum.cycle(n=nil) â an_enumerator
Instance Public methods
Calls block for each element of enum repeatedly
n times or forever if none or nil
is given. If a
non-positive number is given or the collection is empty, does nothing.
Returns nil
if the loop has finished without getting
interrupted.
#cycle saves elements in an internal array so changes to enum after the first pass have no effect.
If no block is given, an enumerator is returned instead.
1 2 3 | a = [ "a" , "b" , "c" ] a.cycle { |x| puts x } # print, a, b, c, a, b, c,.. forever. a.cycle( 2 ) { |x| puts x } # print, a, b, c, a, b, c. |
Please login to continue.