るりまサーチ

最速Rubyリファレンスマニュアル検索!
960件ヒット [1-100件を表示] (0.035秒)
トップページ > クエリ:Enumerator[x] > クエリ:end[x] > 種類:インスタンスメソッド[x]

別のキーワード

  1. enumerator each
  2. each enumerator
  3. enumerator with_index
  4. enumerator with_object
  5. enumerator new

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

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...

絞り込み条件を変える

<< 1 2 3 ... > >>