るりまサーチ

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

別のキーワード

  1. _builtin each_line
  2. io each_line
  3. tracer set_get_line_procs
  4. stringio each_line
  5. pathname each_line

ライブラリ

クラス

検索結果

Enumerator#next -> object (18144.0)

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

...化しません。
つまりもう一度 next を呼ぶと再び例外が発生します。

next
メソッドによる外部列挙の状態は他のイテレータメソッドによる
内部列挙には影響を与えません。
ただし、 IO#each_line のようにおおもとの列挙メカニ...
...enum.next
end
# => 120
# 121
# 122
//}

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

begin
puts enum.next while true
rescue StopIteration
puts "iteration reached at end"
end
# => 120
# 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#next_values -> Array (6210.0)

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

...を配列で返します。

Enumerator#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。

このメソッドは、
yield

yield nil
を区別するために使えます。

next
メソッドによる外部列挙の状...
...each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。

//emlist[例: next next_values の違いを][ruby]{
o = Object.new
def o.each
yield
yield 1
yield 1, 2
yield nil
yield [1, 2]
end
e = o.to_enum
p e.next_val...
...ues
p e.next_values
p e.next_values
p e.next_values
p e.next_values
e = o.to_enum
p e.next
p e.next
p e.next
p e.next
p e.next

## yield args next_values next
# yield [] nil
# yield 1 [1] 1
# yield 1, 2 [1, 2] [1, 2]
# yie...