るりまサーチ

最速Rubyリファレンスマニュアル検索!
44件ヒット [1-44件を表示] (0.055秒)

別のキーワード

  1. _builtin each
  2. _builtin each_line
  3. prime each
  4. each
  5. tsort tsort_each

キーワード

検索結果

Enumerator#next -> object (22.0)

「次」のオブジェクトを返します。

...に最後へ到達しているとき
@see Enumerator#rewind

//emlist[例1][ruby]{
str = "xyz"
enum = str.each_byte

str.bytesize.times do
puts enum.next
end
# => 120
# 121
# 122
//}

//emlist[例2][ruby]{
str = "xyz"
enum = str.each_byte

begin
puts enum.next while true
rescue...
...121
# 122
# iteration reached at end
puts enum.next
#=> 再度 StopIteration 例外が発生
//}

//emlist[例3: Kernel.#loop は StopIteration を捕捉します。][ruby]{
str = "xyz"
enum = str.each_byte
loop do
puts enum.next
end
# => 120
# 121
# 122
//}...

Enumerator#rewind -> self (10.0)

列挙状態を巻き戻します。

...が rewind メソッドを持つとき(respond_to?(:rewind) に
真を返すとき) は、その rewind メソッドを呼び出します。

@see Enumerator#next

//emlist[例][ruby]{
str = "xyz"
enum = str.each_byte

p enum.next # => 120
p enum.next # => 121
enum.rewind
p enum.next # => 120
//}...

Enumerator#with_index(offset = 0) -> Enumerator (10.0)

生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。

...クを指定した場合の戻り値は生成時に指定したレシーバ自身です。

//emlist[例][ruby]{
str = "xyz"

enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]

require "stringio"...
...ータに従って、要素にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator
#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにその...

Enumerator#with_index(offset = 0) {|(*args), idx| ... } -> object (10.0)

生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。

...クを指定した場合の戻り値は生成時に指定したレシーバ自身です。

//emlist[例][ruby]{
str = "xyz"

enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]

require "stringio"...
...ータに従って、要素にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator
#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにその...