Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Enumerableモジュール > cycle

instance method Enumerable#cycle

cycle -> Enumerable::Enumerator
cycle {|obj| ... } -> object | nil

Enumerable オブジェクトの要素を、繰り返し無限に生成し続けます。

Calls block for each element of enum repeatedly forever. Returns nil if and only if the collection is empty. Enumerable#cycle saves elements in an internal array so changes to enum after the first pass have no effect.

[RETURN]
ブロックを指定しなかった場合は、Enumerable::Enumerator を返します。 レシーバが空の場合は nil を返します。
a = ["a", "b", "c"]
a.cycle {|x| puts x }  # print, a, b, c, a, b, c,.. forever.