Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Enumerable::Enumeratorクラス > each

instance method Enumerable::Enumerator#each

each {...} -> object[permalink][rdoc]

生成時のパラメータに従ってブロックを繰り返します。 生成時に指定したイテレータの戻り値をそのまま返します。

例:

str = "Yet Another Ruby Hacker"

enum = Enumerable::Enumerator.new(str, :scan, /\w+/)
enum.each {|word| p word }              # => "Yet"
                                        #    "Another"
                                        #    "Ruby"
                                        #    "Hacker"

str.scan(/\w+/) {|word| p word }        # => "Yet"
                                        #    "Another"
                                        #    "Ruby"
                                        #    "Hacker"