ライブラリ
クラス
-
ARGF
. class (126) - Addrinfo (12)
- Array (348)
- CSV (12)
- Date (48)
- Dir (59)
- Enumerator (212)
-
Enumerator
:: ArithmeticSequence (98) -
Enumerator
:: Chain (42) -
Enumerator
:: Lazy (429) -
Enumerator
:: Yielder (30) -
Etc
:: Group (24) -
Etc
:: Passwd (12) -
Gem
:: SourceIndex (24) - Hash (308)
- IO (162)
- Integer (72)
- Matrix (142)
- Numeric (93)
- Object (63)
- OpenStruct (24)
- Pathname (86)
- Prime (48)
-
Prime
:: PseudoPrimeGenerator (84) -
Psych
:: Nodes :: Node (12) -
REXML
:: Parent (48) - Range (59)
- StopIteration (12)
- String (160)
- StringIO (88)
- Struct (86)
- Vector (74)
-
Zlib
:: GzipReader (36)
モジュール
- Enumerable (789)
- Find (23)
- Kernel (48)
- ObjectSpace (24)
- TSort (66)
オブジェクト
- ENV (256)
-
Readline
:: HISTORY (12)
キーワード
- % (14)
- + (7)
- << (12)
- == (7)
- ArithmeticSequence (7)
- Chain (7)
- Enumerable (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 2
. 6 . 0 (7) -
NEWS for Ruby 2
. 7 . 0 (6) -
NEWS for Ruby 3
. 0 . 0 (5) -
NEWS for Ruby 3
. 1 . 0 (4) - Ruby用語集 (12)
- Yielder (12)
- ascend (12)
- begin (7)
- bsearch (24)
-
bsearch
_ index (10) - build (24)
- bytes (21)
- chain (7)
- chars (21)
- chunk (36)
-
chunk
_ while (21) - codepoints (21)
- collect (72)
- collect! (26)
- collect2 (12)
-
collect
_ concat (36) - combination (12)
- combine (8)
- compact (4)
- cycle (36)
-
delete
_ if (72) - descend (12)
- detect (24)
- downto (24)
- drop (12)
-
drop
_ while (48) - each (436)
- each2 (12)
-
each
_ byte (60) -
each
_ char (48) -
each
_ child (59) -
each
_ codepoint (48) -
each
_ cons (24) -
each
_ entry (27) -
each
_ grapheme _ cluster (16) -
each
_ index (24) -
each
_ key (24) -
each
_ line (108) -
each
_ object (24) -
each
_ pair (96) -
each
_ prime (24) -
each
_ slice (24) -
each
_ strongly _ connected _ component (22) -
each
_ strongly _ connected _ component _ from (22) -
each
_ value (48) -
each
_ with _ index (60) -
each
_ with _ object (24) - eager (6)
- end (7)
-
enum
_ for (48) -
exclude
_ end? (7) - feed (12)
- filter (70)
- filter! (35)
-
filter
_ map (18) - find (70)
-
find
_ all (36) -
find
_ index (72) - first (14)
-
flat
_ map (36) - force (12)
- foreach (60)
- grep (12)
-
grep
_ v (10) -
group
_ by (24) - gsub (84)
- gsub! (48)
- hash (7)
- index (36)
- inspect (14)
-
keep
_ if (60) - last (14)
- lazy (24)
- lines (49)
- loop (12)
- map (72)
- map! (26)
-
max
_ by (48) -
min
_ by (48) -
minmax
_ by (24) - new (38)
- next (12)
-
next
_ values (12) - partition (24)
- peek (12)
-
peek
_ values (12) - permutation (24)
- produce (6)
- reject (96)
- reject! (60)
-
repeated
_ combination (12) -
repeated
_ permutation (24) - result (12)
-
reverse
_ each (38) - rewind (31)
- rindex (12)
-
ruby 1
. 9 feature (12) - select (120)
- select! (60)
- size (26)
-
slice
_ after (46) -
slice
_ before (60) -
slice
_ when (23) -
sort
_ by (24) -
sort
_ by! (12) - step (131)
- take (12)
-
take
_ while (60) - then (7)
- times (12)
-
to
_ enum (48) -
to
_ proc (6) -
transform
_ keys (8) -
transform
_ keys! (8) -
transform
_ values (18) -
transform
_ values! (18) -
tsort
_ each (22) - uniq (18)
- upto (48)
-
with
_ index (60) -
with
_ object (48) - yield (12)
-
yield
_ self (8) - zip (24)
検索結果
先頭5件
-
Enumerator (44024.0)
-
each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。
...each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。
また、外部イテレータとしても使えます。
Enumerable モジュールは、 Module#include 先のクラスが持つ
each メソッドを元に様々なメソッドを提供し......されます。
Enumerator を介することにより String#each_byte のような
異なる名前のイテレータについても each と同様に Enumerable の機能を利用できます。
Enumerator を生成するには Enumerator.newあるいは
Object#to_enum, Object#enum_for を利用......
enumerator を生成して返します。
=== 注意
外部イテレータとしての機能は Fiber を用いて実装されているため Fiber と同じ制限があります。
例えば以下のようなスレッドをまたいだ呼び出しはエラーになります。
//emlist[例][ruby... -
Enumerator
. produce(initial = nil) { |prev| . . . } -> Enumerator (27265.0) -
与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。 ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。 initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロック 呼び出しの引数として渡されます。initial が渡されなかった場合は nil が 渡されます。
...与えられたブロックを呼び出し続ける、停止しない Enumerator を返します。
ブロックの戻り値が、次にブロックを呼び出す時に引数として渡されます。
initial 引数が渡された場合、最初にブロックを呼び出す時にそれがブロ......//emlist[例][ruby]{
# 1, 2, 3, 4, ... と続く Enumerator
Enumerator.produce(1, &:succ)
# next を呼ぶたびランダムな数値を返す Enumerator
Enumerator.produce { rand(10) }
# ツリー構造の祖先ノードを列挙する Enumerator
ancestors = Enumerator.produce(node) { |prev| no......ソッドは Enumerable の各メソッドと組み合わせて使うことで、
while や until ループのような処理を実装できます。
例えば Enumerable#detect, Enumerable#slice_after, Enumerable#take_while
などと合わせて使えるでしょう。
//emlist[Enumerable のメ... -
Enumerator
# peek _ values -> Array (27152.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.n......ext
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
# next _ values -> Array (27124.0) -
「次」のオブジェクトを配列で返します。
...「次」のオブジェクトを配列で返します。
Enumerator#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。
このメソッドは、
yield
と
yield nil
を区別するために使えます。
next メソッ......alues の違いを][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......[1] 1
# yield 1, 2 [1, 2] [1, 2]
# yield nil [nil] nil
# yield [1, 2] [[1, 2]] [1, 2]
//}
@raise StopIteration 列挙状態が既に最後へ到達しているとき
@see Enumerator#next, Enumerator#peek, Enumerator#peek_values... -
Enumerator
# +(enum) -> Enumerator :: Chain (24317.0) -
自身と enum 引数を続けて繰り返す Enumerator::Chain を返します。
...自身と enum 引数を続けて繰り返す Enumerator::Chain を返します。
//emlist[例][ruby]{
e = (1..3).each + [4, 5]
e.to_a #=> [1, 2, 3, 4, 5]
//}
@see Enumerable#chain... -
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
# with _ object(obj) -> Enumerator (24219.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
. new(obj , method = :each , *args) -> Enumerator (24215.0) -
オブジェクト obj について、 each の代わりに method という 名前のメソッドを使って繰り返すオブジェクトを生成して返します。 args を指定すると、 method の呼び出し時に渡されます。
...method イテレータメソッドの名前を表すシンボルまたは文字列
@param args イテレータメソッドの呼び出しに渡す任意個の引数
//emlist[例][ruby]{
str = "xyz"
enum = Enumerator.new(str, :each_byte)
p enum.map {|b| '%02x' % b } # => ["78", "79", "7a"]
//}... -
Enumerator
# with _ index(offset = 0) -> Enumerator (24213.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 "stringio"
StringIO.new("foo|bar|baz").each("|").with_inde......ータに従って、要素にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにその... -
Enumerator
# each(*args) -> Enumerator (24207.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *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"
# "Ruby"......# "Ruby"
# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/) # => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_......turned
end
enum = obj.to_enum :each_arg, :a, :x
enum.each.to_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum...