るりまサーチ

最速Rubyリファレンスマニュアル検索!
66件ヒット [1-66件を表示] (0.166秒)
トップページ > 種類:インスタンスメソッド[x] > クエリ:n[x] > クエリ:next[x] > クラス:Enumerator[x]

別のキーワード

  1. etc sc_xopen_enh_i18n
  2. rsa n
  3. rsa n=
  4. pop n_bytes
  5. openssl n

ライブラリ

キーワード

検索結果

Enumerator#next -> object (24239.0)

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

...
列挙が既に最後へ到達している場合は、
StopIteration 例外を発生します。このとき列挙状態は変化しません。
つまりもう一度 next を呼ぶと再び例外が発生します。

next
メソッドによる外部列挙の状態は他のイテレータメソ...
...だし、 IO#each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。

@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#rewind

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

s...
...ts 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...

Enumerator#next_values -> Array (12305.0)

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

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

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

このメソッドは、
yield

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

next
メソッドによる外部列挙...
...ach_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_valu...
...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]
# yield nil...

Enumerator#rewind -> self (6132.0)

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

...

next
メソッドによる外部列挙の状態を最初まで巻き戻します。 self を返します。

内包するオブジェクトが rewind メソッドを持つとき(respond_to?(:rewind) に
真を返すとき) は、その rewind メソッドを呼び出します。

@see Enumerator#n...
...ext

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

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

Enumerator#feed(obj) -> nil (3126.0)

Enumerator 内部の yield が返す値を設定します。

...
Enumerator
内部の yield が返す値を設定します。

これで値を設定しなかった場合は yield は nil を返します。

この値は内部で yield された時点でクリアされます。

//emlist[例][ruby]{
# (1), (2), ... (10) の順に実行される
o = Object.new
def...
...# (8) => nil
x = yield # (9) blocks
p x # not reached w/o another e.next
end

e = o.to_enum
e.next # (1)
e.feed "foo" # (3)
e.next # (4)
e.next # (7)
# (10)
//}

@param obj Enumerator 内部の yield...

Enumerator#peek_values -> Array (3072.0)

Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。

...
Enumerator
#next_values のように「次」のオブジェクトを
配列で返しますが、列挙状態を変化させません。

Enumerator
#next, Enumerator#next_values のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next
と異なり...
...topIteration 例外を発生します。

このメソッドは Enumerator#next_values と同様
yield

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

//emlist[例][ruby]{
o = Object.new
def o.each
yield
yield 1
yield 1, 2
end
e = o.to_enum
p e.peek_values #=> []
e.next
p e.peek_...
...values #=> [1]
p e.peek_values #=> [1]
e.next
p e.peek_values #=> [1, 2]
e.next
p e.peek_values # raises StopIteration
//}

@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#next_values, Enumerator#peek_values...

絞り込み条件を変える

Enumerator#peek -> object (3050.0)

「次」のオブジェクトを返しますが、列挙状態を変化させません。

...を変化させません。

Enumerator
#next のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next
と異なり列挙状態を変更しません。

列挙が既に最後へ到達している場合は、StopIteration 例外を発生します。...
...]
e = a.to_enum
p e.next #=> 1
p e.peek #=> 2
p e.peek #=> 2
p e.peek #=> 2
p e.next #=> 2
p e.next #=> 3
p e.next #raises StopIteration
//}

@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#next_values, Enumerator#peek_values...