クラス
-
ARGF
. class (88) - Array (44)
- Enumerator (110)
-
Enumerator
:: ArithmeticSequence (30) -
Enumerator
:: Lazy (44) -
Enumerator
:: Yielder (27) - IO (44)
- Matrix (22)
- Numeric (84)
- Object (44)
- Pathname (44)
- Prime (22)
-
Prime
:: PseudoPrimeGenerator (44) - StopIteration (11)
- String (44)
-
Zlib
:: GzipReader (66)
モジュール
- Enumerable (132)
- TSort (60)
キーワード
- << (11)
- == (6)
- ascend (22)
- begin (6)
- chunk (11)
- descend (22)
- each (154)
-
each
_ byte (66) -
each
_ codepoint (22) -
each
_ entry (22) -
each
_ index (22) -
each
_ line (88) -
each
_ strongly _ connected _ component (20) -
each
_ strongly _ connected _ component _ from (20) -
each
_ with _ index (66) -
enum
_ for (44) -
exclude
_ end? (6) - feed (11)
- hash (6)
- lazy (11)
-
max
_ by (44) - next (11)
-
next
_ values (11) -
peek
_ values (11) - result (11)
-
sort
_ by (22) - step (84)
-
to
_ enum (44) -
to
_ proc (5) -
tsort
_ each (20) -
with
_ index (22) -
with
_ object (22) - yield (11)
検索結果
先頭5件
-
Enumerator
# with _ object(obj) -> Enumerator (21138.0) -
繰り返しの各要素に 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
# =>... -
Enumerator
# each(*args) -> Enumerator (21114.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"......an).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_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm... -
Enumerator
:: ArithmeticSequence # end -> Numeric | nil (21108.0) -
末項(終端)を返します。
...末項(終端)を返します。
@see Enumerator::ArithmeticSequence#begin... -
Enumerator
# peek _ values -> Array (21059.0) -
Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。
...
Enumerator#next_values のように「次」のオブジェクトを
配列で返しますが、列挙状態を変化させません。
Enumerator#next, Enumerator#next_values のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next と異なり......Iteration 例外を発生します。
このメソッドは 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_val......ues #=> [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
# with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (21038.0) -
繰り返しの各要素に 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
# =>... -
Enumerator
# next -> object (21037.0) -
「次」のオブジェクトを返します。
...ます。
@raise 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.e......ached 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
#... -
Enumerator
# next _ values -> Array (21031.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.......[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
# feed(obj) -> nil (21029.0) -
Enumerator 内部の yield が返す値を設定します。
...
Enumerator 内部の yield が返す値を設定します。
これで値を設定しなかった場合は yield は nil を返します。
この値は内部で yield された時点でクリアされます。
//emlist[例][ruby]{
# (1), (2), ... (10) の順に実行される
o = Object.new
def......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 が返す値
@raise TypeError すでに値... -
Enumerator
# each -> self (21014.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"......an).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_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm... -
Enumerator
# each { . . . } -> object (21014.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"......an).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_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |elm...