66件ヒット
[1-66件を表示]
(0.144秒)
ライブラリ
- ビルトイン (66)
クラス
- Enumerator (55)
- StopIteration (11)
キーワード
- feed (11)
-
next
_ values (11) -
peek
_ values (11) - result (11)
- rewind (11)
検索結果
先頭5件
-
Enumerator
# next -> object (26162.0) -
「次」のオブジェクトを返します。
...変化しません。
つまりもう一度 next を呼ぶと再び例外が発生します。
next メソッドによる外部列挙の状態は他のイテレータメソッドによる
内部列挙には影響を与えません。
ただし、 IO#each_line のようにおおもとの列挙メカ......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 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 (14216.0) -
「次」のオブジェクトを配列で返します。
...を配列で返します。
Enumerator#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。
このメソッドは、
yield
と
yield nil
を区別するために使えます。
next メソッドによる外部列挙の状......O#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_v......alues
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]
# y... -
Enumerator
# peek _ values -> Array (8077.0) -
Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。
...Enumerator#next_values のように「次」のオブジェクトを
配列で返しますが、列挙状態を変化させません。
Enumerator#next, Enumerator#next_values のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next と異なり......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_va......lues #=> [1, 2]
e.next
p e.peek_values # raises StopIteration
//}
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#next_values, Enumerator#peek_values... -
Enumerator
# rewind -> self (8037.0) -
列挙状態を巻き戻します。
...列挙状態を巻き戻します。
next メソッドによる外部列挙の状態を最初まで巻き戻します。 self を返します。
内包するオブジェクトが 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
//}... -
StopIteration
# result -> object (8037.0) -
この例外オブジェクトを発生させる原因となったメソッド等の返り値を返します。
...ect = Object.new
def object.each
yield :yield1
yield :yield2
:each_returned
end
enumerator = object.to_enum
p enumerator.next #=> :yield1
p enumerator.next #=> :yield2
begin
enumerator.next
rescue StopIteration => error
p error.result #=> :each_returned
end... -
Enumerator
# feed(obj) -> nil (8031.0) -
Enumerator 内部の yield が返す値を設定します。
...る
o = Object.new
def o.each
x = yield # (2) blocks
p x # (5) => "foo"
x = yield # (6) blocks
p x # (8) => nil
x = yield # (9) blocks
p x # not reached w/o another e.next
end
e = o.to_enum
e.next # (1)
e.fee......d "foo" # (3)
e.next # (4)
e.next # (7)
# (10)
//}
@param obj Enumerator 内部の yield が返す値
@raise TypeError すでに値をこのメソッドでセットしている場合に発生します...