ライブラリ
クラス
-
ARGF
. class (202) - Addrinfo (24)
- Array (660)
- CSV (24)
- Date (72)
- Dir (118)
- Enumerator (212)
-
Enumerator
:: ArithmeticSequence (98) -
Enumerator
:: Chain (42) -
Enumerator
:: Lazy (429) -
Enumerator
:: Yielder (30) -
Etc
:: Group (24) -
Etc
:: Passwd (24) -
Gem
:: SourceIndex (12) - Hash (291)
- IO (274)
- Integer (96)
- Matrix (236)
- Numeric (93)
- Object (78)
- OpenStruct (24)
- Pathname (126)
- Prime (48)
-
Prime
:: PseudoPrimeGenerator (84) -
Psych
:: Nodes :: Node (12) -
REXML
:: Parent (96) - Range (97)
- StopIteration (12)
- String (208)
- StringIO (176)
- Struct (86)
- Vector (160)
-
Zlib
:: GzipReader (48)
モジュール
- Enumerable (777)
- Find (23)
- Kernel (60)
- ObjectSpace (48)
- TSort (132)
オブジェクト
- ENV (215)
-
Readline
:: HISTORY (24)
キーワード
- % (14)
- + (7)
- << (12)
- == (7)
- ArithmeticSequence (7)
- Chain (7)
- Fiber (12)
- Lazy (12)
-
NEWS for Ruby 2
. 0 . 0 (12) -
NEWS for Ruby 2
. 2 . 0 (11) -
NEWS for Ruby 2
. 3 . 0 (10) -
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 3
. 1 . 0 (4) - Yielder (12)
- ascend (24)
- begin (7)
- bsearch (48)
-
bsearch
_ index (20) - build (24)
- bytes (42)
- chain (7)
- chars (28)
- chunk (36)
-
chunk
_ while (21) - codepoints (42)
- collect (108)
- collect! (52)
- collect2 (24)
-
collect
_ concat (36) - combination (24)
- combine (16)
- compact (4)
- cycle (36)
-
delete
_ if (96) - descend (24)
- detect (24)
- downto (48)
- drop (12)
-
drop
_ while (60) - each (544)
- each2 (24)
-
each
_ byte (120) -
each
_ char (72) -
each
_ child (94) -
each
_ codepoint (96) -
each
_ cons (24) -
each
_ entry (30) -
each
_ grapheme _ cluster (16) -
each
_ index (36) -
each
_ key (24) -
each
_ line (180) -
each
_ object (48) -
each
_ pair (72) -
each
_ prime (24) -
each
_ slice (24) -
each
_ strongly _ connected _ component (44) -
each
_ strongly _ connected _ component _ from (44) -
each
_ value (24) -
each
_ with _ index (72) -
each
_ with _ object (24) - eager (6)
- end (7)
-
enum
_ for (48) -
exclude
_ end? (7) - feed (12)
- filter (77)
- filter! (42)
-
filter
_ map (18) - find (71)
-
find
_ all (36) -
find
_ index (108) - first (14)
-
flat
_ map (36) - force (12)
- foreach (120)
- grep (12)
-
grep
_ v (10) -
group
_ by (12) - gsub (84)
- gsub! (48)
- hash (7)
- index (72)
- inspect (14)
-
keep
_ if (62) - last (14)
- lazy (24)
- lines (84)
- loop (24)
- map (108)
- map! (52)
- map2 (12)
-
max
_ by (48) -
min
_ by (48) -
minmax
_ by (24) - new (38)
- next (12)
-
next
_ values (12) - optparse (12)
- partition (24)
- peek (12)
-
peek
_ values (12) - permutation (24)
- produce (6)
- reject (108)
- reject! (72)
-
repeated
_ combination (24) -
repeated
_ permutation (24) - result (12)
-
reverse
_ each (52) - rewind (31)
- rindex (36)
-
ruby 1
. 9 feature (12) - select (132)
- select! (72)
- size (26)
-
slice
_ after (46) -
slice
_ before (60) -
slice
_ when (23) -
sort
_ by (24) -
sort
_ by! (24) - step (155)
- take (12)
-
take
_ while (72) - then (14)
- times (24)
-
to
_ enum (48) -
to
_ proc (6) -
transform
_ keys (20) -
transform
_ keys! (20) -
transform
_ values (18) -
transform
_ values! (18) -
tsort
_ each (44) - uniq (18)
- upto (48)
-
with
_ index (60) -
with
_ object (48) - yield (12)
-
yield
_ self (16) - zip (24)
検索結果
先頭5件
-
Enumerator (44036.0)
-
each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。
...義されます。
Enumerator を介することにより String#each_byte のような
異なる名前のイテレータについても each と同様に Enumerable の機能を利用できます。
Enumerator を生成するには Enumerator.newあるいは
Object#to_enum, Object#enum_for を利......に
enumerator を生成して返します。
=== 注意
外部イテレータとしての機能は Fiber を用いて実装されているため Fiber と同じ制限があります。
例えば以下のようなスレッドをまたいだ呼び出しはエラーになります。
//emlist[例][r......uby]{
a = nil
Thread.new do
a = [1, 2, 3].each
a.next
end.join
p a.next
#=> t.rb:7:in `next': fiber called across threads (FiberError)
# from t.rb:7:in `<main>'
//}... -
Enumerator
# with _ object(obj) -> Enumerator (27219.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}"
e......nd
# => foo:0
# => foo:1
# => foo:2
//}
@param obj 繰り返しの各要素に添えて渡されるオブジェクト
@see Enumerable#each_with_object... -
Enumerator
# with _ index(offset = 0) -> Enumerator (27213.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
...デックスは 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"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["foo|", 1]
# ["bar|", 2]
# ["baz", 3]
//}
生成時のパラメータに従って、要素にインデックスを添えてブロックを繰り......返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。... -
Enumerator
# next -> object (27206.0) -
「次」のオブジェクトを返します。
...ます。
列挙が既に最後へ到達している場合は、
StopIteration 例外を発生します。このとき列挙状態は変化しません。
つまりもう一度 next を呼ぶと再び例外が発生します。
next メソッドによる外部列挙の状態は他のイテレータ......aise StopIteration 列挙状態が既に最後へ到達しているとき
@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
beg......uts 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]{
st... -
Enumerator
# next _ values -> Array (27124.0) -
「次」のオブジェクトを配列で返します。
...クトを配列で返します。
Enumerator#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。
このメソッドは、
yield
と
yield nil
を区別するために使えます。
next メソッドによる外部列挙....../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_values
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]
# yield nil [nil] nil
# yield [1, 2] [[1, 2]] [1, 2]
//}
@raise StopIteration 列挙状態が既に最... -
Enumerator
# with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (27119.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}"
e......nd
# => foo:0
# => foo:1
# => foo:2
//}
@param obj 繰り返しの各要素に添えて渡されるオブジェクト
@see Enumerable#each_with_object... -
Enumerator
# with _ index(offset = 0) {|(*args) , idx| . . . } -> object (27113.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
...デックスは 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"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["foo|", 1]
# ["bar|", 2]
# ["baz", 3]
//}
生成時のパラメータに従って、要素にインデックスを添えてブロックを繰り......返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。... -
Enumerator
. new(size=nil) {|y| . . . } -> Enumerator (24265.0) -
Enumerator オブジェクトを生成して返します。与えられたブロックは Enumerator::Yielder オブジェクトを 引数として実行されます。
...
Enumerator オブジェクトを生成して返します。与えられたブロックは Enumerator::Yielder オブジェクトを
引数として実行されます。
生成された Enumerator オブジェクトに対して each を呼ぶと、この生成時に指定されたブロックを......する Enumerator オブジェクトの要素数を指定します。
Integer、Float::INFINITY、Proc オブジェク
ト、nil のいずれかを指定します。Enumerator#size の実
行時に参照されます。
//emlist[例][ruby]{
enum = Enumerator.new{|......y|
(1..10).each{|i|
y << i if i % 5 == 0
}
}
enum.each{|i| p i }
#=> 5
# 10
fib = Enumerator.new { |y|
a = b = 1
loop {
y << a
a, b = b, a + b
}
}
p fib.take(10) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
//}... -
Enumerator
. produce(initial = nil) { |prev| . . . } -> Enumerator (24265.0) -
与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。 ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。 initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロック 呼び出しの引数として渡されます。initial が渡されなかった場合は nil が 渡されます。
...ない Enumerator を返します。
ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。
initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロック
呼び出しの引数として渡されます。initial......が例外 StopIterationを投げた場合、繰り返しが終了します。
@param initial ブロックに最初に渡される値です。任意のオブジェクトを渡せます。
//emlist[例][ruby]{
# 1, 2, 3, 4, ... と続く Enumerator
Enumerator.produce(1, &:succ)
# next を呼ぶた......ダムな数値を返す Enumerator
Enumerator.produce { rand(10) }
# ツリー構造の祖先ノードを列挙する Enumerator
ancestors = Enumerator.produce(node) { |prev| node = prev.parent or raise StopIteration }
enclosing_section = ancestors.find { |n| n.type == :section }
//}
このメソ... -
Enumerator
. new(size=nil) {|y| . . . } -> Enumerator (24263.0) -
Enumerator オブジェクトを生成して返します。与えられたブロックは Enumerator::Yielder オブジェクトを 引数として実行されます。
...
Enumerator オブジェクトを生成して返します。与えられたブロックは Enumerator::Yielder オブジェクトを
引数として実行されます。
生成された Enumerator オブジェクトに対して each を呼ぶと、この生成時に指定されたブロックを......する Enumerator オブジェクトの要素数を指定します。
Integer、Float::INFINITY、Proc オブジェク
ト、nil のいずれかを指定します。Enumerator#size の実
行時に参照されます。
//emlist[例][ruby]{
enum = Enumerator.new{|......y|
(1..10).each{|i|
y << i if i % 5 == 0
}
}
enum.each{|i| p i }
#=> 5
# 10
fib = Enumerator.new { |y|
a = b = 1
loop {
y << a
a, b = b, a + b
}
}
p fib.take(10) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
//}...