cycle

ary.cycle(n=nil) { |obj| block } â nil
ary.cycle(n=nil) â Enumerator
Instance Public methods

Calls the given block for each element n times or forever if nil is given.

Does nothing if a non-positive number is given or the array is empty.

Returns nil if the loop has finished without getting interrupted.

If no block is given, an Enumerator is returned instead.

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.
doc_ruby_on_rails
2015-03-30 16:14:30
Comments
Leave a Comment

Please login to continue.