種類
- インスタンスメソッド (648)
- モジュール関数 (33)
- クラス (11)
クラス
-
ARGF
. class (66) - Array (61)
- Enumerator (143)
-
Enumerator
:: Chain (18) -
Enumerator
:: Lazy (55) -
Enumerator
:: Yielder (22) - Object (57)
- Range (11)
- StopIteration (11)
- Struct (17)
モジュール
- Enumerable (187)
- Kernel (11)
- ObjectSpace (22)
キーワード
- << (11)
- bsearch (22)
- collect (22)
- cycle (11)
- detect (11)
- each (78)
-
each
_ byte (11) -
each
_ char (11) -
each
_ line (22) -
each
_ object (22) -
each
_ with _ object (11) -
enum
_ for (44) - feed (11)
- filter (18)
-
filter
_ map (5) - find (11)
-
find
_ all (11) - force (11)
- loop (11)
- map (22)
-
max
_ by (22) -
min
_ by (22) -
minmax
_ by (11) - next (11)
-
next
_ values (11) - partition (11)
- peek (11)
-
peek
_ values (11) - reject (22)
- result (11)
- rewind (6)
- select (33)
-
sort
_ by (11) - then (6)
-
to
_ enum (44) -
with
_ index (22) -
with
_ object (22) - yield (11)
-
yield
_ self (7)
検索結果
先頭5件
-
Enumerator (44038.0)
-
each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。
...義されます。
Enumerator を介することにより String#each_byte のような
異なる名前のイテレータについても each と同様に Enumerable の機能を利用できます。
Enumerator を生成するには Enumerator.newあるいは
Object#to_enum, Object#enum_for を利......用します。また、一部の
イテレータはブロックを渡さずに呼び出すと繰り返しを実行する代わりに
enumerator を生成して返します。
=== 注意
外部イテレータとしての機能は Fiber を用いて実装されているため Fiber と同じ制限... -
Enumerator
# with _ object(obj) -> Enumerator (30336.0) -
繰り返しの各要素に obj を添えてブロックを繰り返し、obj を返り値として返します。
...しを実行し、
最後に obj を返す Enumerator を返します。
//emlist[例][ruby]{
# 0,1,2 と呼びだす enumeratorを作る
to_three = Enumerator.new do |y|
3.times do |x|
y << x
end
end
to_three_with_string = to_three.with_object("foo")
to_three_with_string.each do |x,string......|
puts "#{string}: #{x}"
end
# => foo:0
# => foo:1
# => foo:2
//}
@param obj 繰り返しの各要素に添えて渡されるオブジェクト
@see Enumerable#each_with_object... -
Enumerator
# with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (30236.0) -
繰り返しの各要素に obj を添えてブロックを繰り返し、obj を返り値として返します。
...しを実行し、
最後に obj を返す Enumerator を返します。
//emlist[例][ruby]{
# 0,1,2 と呼びだす enumeratorを作る
to_three = Enumerator.new do |y|
3.times do |x|
y << x
end
end
to_three_with_string = to_three.with_object("foo")
to_three_with_string.each do |x,string......|
puts "#{string}: #{x}"
end
# => foo:0
# => foo:1
# => foo:2
//}
@param obj 繰り返しの各要素に添えて渡されるオブジェクト
@see Enumerable#each_with_object... -
Enumerator
# each(*args) -> Enumerator (24217.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...戻り値をそのまま返します。
@param args 末尾へ追加する引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"......llo, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end
enum = obj.to_enum :each_arg, :a, :x
enum.each.to... -
Enumerator
# with _ index(offset = 0) -> Enumerator (24216.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......ータに従って、要素にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにその... -
Enumerator
# peek -> object (24127.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... -
Enumerator
# next -> object (24121.0) -
「次」のオブジェクトを返します。
...じて「次」のオブジェクトを返し、列挙状態を1つ分進めます。
列挙が既に最後へ到達している場合は、
StopIteration 例外を発生します。このとき列挙状態は変化しません。
つまりもう一度 next を呼ぶと再び例外が発生します......の列挙メカニズムが副作用を
伴っている場合には影響があり得ます。
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#rewind
//emlist[例1][ruby]{
str = "xyz"
enum = str.each_byte
str.bytesize.times do
puts enum.next
end
#......s 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... -
Enumerator
# each { . . . } -> object (24117.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...戻り値をそのまま返します。
@param args 末尾へ追加する引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"......llo, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end
enum = obj.to_enum :each_arg, :a, :x
enum.each.to... -
Enumerator
# each(*args) { . . . } -> object (24117.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...戻り値をそのまま返します。
@param args 末尾へ追加する引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"......llo, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end
enum = obj.to_enum :each_arg, :a, :x
enum.each.to... -
Enumerator
# with _ index(offset = 0) {|(*args) , idx| . . . } -> object (24116.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......ータに従って、要素にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにその...