るりまサーチ

最速Rubyリファレンスマニュアル検索!
275件ヒット [1-100件を表示] (0.039秒)

別のキーワード

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

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 3 > >>

Enumerator#each(*args) -> Enumerator (27289.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"...
...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_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e...
...lm| elm } # => :method_returned

enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}...

Enumerator#each -> self (27189.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"...
...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_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e...
...lm| elm } # => :method_returned

enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}...

Enumerator#each {...} -> object (27189.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"...
...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_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e...
...lm| elm } # => :method_returned

enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}...

Enumerator#each(*args) {...} -> object (27189.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"...
...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_a # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e...
...lm| elm } # => :method_returned

enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}...

Enumerator::Yielder#yield(*object) -> () (24171.0)

Enumerator.new で使うメソッドです。

...
Enumerator
.new で使うメソッドです。

生成された Enumerator オブジェクトの each メソッドを呼ぶと
Enumerator
::Yielder オブジェクトが渡されたブロックが実行され、
ブロック内の yield メソッドが呼ばれるたびに each に渡された
ブロ...
...ックが yield メソッドに渡された値とともに繰り返されます。

//emlist[例][ruby]{
enum = Enumerator.new do |y|
y.yield 1, 2, 3
end

enum.each do |x, y, z|
p [x, y, z]
end
# => [1, 2, 3]
//}...

絞り込み条件を変える

Enumerator#next_values -> Array (9114.0)

「次」のオブジェクトを配列で返します。

...「次」のオブジェクトを配列で返します。

Enumerator
#next とほぼ同様の挙動をします。終端まで到達した場合は
StopIteration 例外を発生させます。

このメソッドは、
yield


yield
nil
を区別するために使えます。

next メソッ...
...ただし、 IO#each_line のようにおおもとの列挙メカニズムが副作用を
伴っている場合には影響があり得ます。

//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_...
...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]
//}

@r...

Enumerator#peek_values -> Array (9088.0)

Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。

...
Enumerator
#next_values のように「次」のオブジェクトを
配列で返しますが、列挙状態を変化させません。

Enumerator
#next, Enumerator#next_values のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next と異なり...
...StopIteration 例外を発生します。

このメソッドは 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.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#feed(obj) -> nil (9080.0)

Enumerator 内部の yield が返す値を設定します。

...
Enumerator
内部の yield が返す値を設定します。

これで値を設定しなかった場合は yield は nil を返します。

この値は内部で yield された時点でクリアされます。

//emlist[例][ruby]{
# (1), (2), ... (10) の順に実行される
o = Object.new
def...
...o.each
x = yield # (2) blocks
p x # (5) => "foo"
x = yield # (6) blocks
p x # (8) => nil
x = yield # (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 すでに値をこのメソッドでセットしている場合に発生します...

Enumerable#each_entry -> Enumerator (6233.0)

ブロックを各要素に一度ずつ適用します。

...配列として渡されます。

//emlist[例][ruby]{
class Foo
include Enumerable
def each
yield
1
yield
1,2
end
end
Foo.new.each_entry{|o| print o, " -- "}
# => 1 -- [1, 2] --
//}

ブロックを省略した場合は Enumerator が返されます。

@see Enumerable#slice_before...

Pathname#each_entry -> Enumerator (6231.0)

Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。

...Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
require "pathname"

Pathname("/usr/local").each_entry {|f| p f }

# => #<Pathname:.>
# => #<Pathname:..>
# => #<Pathname:bin>
# => #<Pathna...
...me:etc>
# => #<Pathname:include>
# => #<Pathname:lib>
# => #<Pathname:opt>
//}

@see Dir.foreach...

絞り込み条件を変える

<< 1 2 3 > >>