るりまサーチ

最速Rubyリファレンスマニュアル検索!
988件ヒット [301-400件を表示] (0.050秒)

別のキーワード

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

検索結果

<< < ... 2 3 4 5 6 ... > >>

Prime.each(upper_bound = nil, generator = EratosthenesGenerator.new) -> Enumerator (209.0)

Prime.instance.each と同じです。

...

@param generator 素数生成器のインスタンスを指定します。

@return ブロックの最後に評価された値を返します。
ブロックが与えられなかった場合は、Enumerator と互換性のある外部イテレータを返します。


@see Prime#each...

Object#enum_for(method = :each, *args) -> Enumerator (166.0)

Enumerator.new(self, method, *args) を返します。

...
Enumerator
.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...or(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} i...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (166.0)

Enumerator.new(self, method, *args) を返します。

...
Enumerator
.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...or(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} i...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#to_enum(method = :each, *args) -> Enumerator (166.0)

Enumerator.new(self, method, *args) を返します。

...
Enumerator
.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...or(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} i...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#to_enum(method = :each, *args) {|*args| ... } -> Enumerator (166.0)

Enumerator.new(self, method, *args) を返します。

...
Enumerator
.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...or(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} i...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

絞り込み条件を変える

Kernel.#loop -> Enumerator (135.0)

(中断されない限り)永遠にブロックの評価を繰り返します。 ブロックが指定されなければ、代わりに Enumerator を返します。

...れば、代わりに Enumerator を返します。

//emlist[例][ruby]{
loop do
print "Input: "
line = gets
break if !line or line =~ /^qQ/
# ...
end
//}

与えられたブロック内で StopIteration を Kernel.#raise すると
ループを終了して Enumerator が最後に返した...
...値を返します。
ループを終了させる場合、通常は break を使用してください。

//emlist[例][ruby]{
enum = Enumerator.new { |y|
y << "one"
y << "two"
:ok
}

result = loop {
puts enum.next
} # => :ok
//}


@return break の引数など、ループ脱出時の値を...

ObjectSpace.#each_object -> Enumerator (132.0)

指定された klass と Object#kind_of? の関係にある全ての オブジェクトに対して繰り返します。引数が省略された時には全てのオブ ジェクトに対して繰り返します。 繰り返した数を返します。

...のオブ
ジェクトに対して繰り返します。
繰り返した数を返します。

ブロックが与えられなかった場合は、
Enumerator
オブジェクトを返します。

次のクラスのオブジェクトについては繰り返しません

* Fixnum
* Symbol
* TrueClas...
...す。

@param klass クラスかモジュールを指定します。

//emlist[例: ブロックなし][ruby]{
p ObjectSpace.each_object
# => #<Enumerator: ObjectSpace:each_object(false)>
//}

//emlist[例: 全てのオブジェクトを扱う][ruby]{
ObjectSpace.each_object.take(5).each { |x| p x...
...ss_names"
# => "@corrections"
# => Total count: 9938
//}

//emlist[例: 任意のクラスを扱う][ruby]{
Person = Struct.new(:name)
s1 = Person.new("tanaka")
s2 = Person.new("sato")

count = ObjectSpace.each_object(Person) { |x| p x }
puts "Total count: #{count}"

# => #<struct Person name="sato"...

ObjectSpace.#each_object(klass) -> Enumerator (132.0)

指定された klass と Object#kind_of? の関係にある全ての オブジェクトに対して繰り返します。引数が省略された時には全てのオブ ジェクトに対して繰り返します。 繰り返した数を返します。

...のオブ
ジェクトに対して繰り返します。
繰り返した数を返します。

ブロックが与えられなかった場合は、
Enumerator
オブジェクトを返します。

次のクラスのオブジェクトについては繰り返しません

* Fixnum
* Symbol
* TrueClas...
...す。

@param klass クラスかモジュールを指定します。

//emlist[例: ブロックなし][ruby]{
p ObjectSpace.each_object
# => #<Enumerator: ObjectSpace:each_object(false)>
//}

//emlist[例: 全てのオブジェクトを扱う][ruby]{
ObjectSpace.each_object.take(5).each { |x| p x...
...ss_names"
# => "@corrections"
# => Total count: 9938
//}

//emlist[例: 任意のクラスを扱う][ruby]{
Person = Struct.new(:name)
s1 = Person.new("tanaka")
s2 = Person.new("sato")

count = ObjectSpace.each_object(Person) { |x| p x }
puts "Total count: #{count}"

# => #<struct Person name="sato"...

IO#each(limit, chomp: false) -> Enumerator (130.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...を引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator
オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数...
...す。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: A...
...読み取りバイト数に 10 を指定][ruby]{
IO.write("testfile", "This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is l...

IO#each(rs = $/, chomp: false) -> Enumerator (130.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...を引数として
与えられたブロックを実行します。

ブロックが与えられなかった場合は、自身から生成した
Enumerator
オブジェクトを返します。

テキスト読み込みメソッドとして動作します。

limit で最大読み込みバイト数...
...す。

//emlist[例: 引数なし][ruby]{
IO.write("testfile", "This is line one,\nThis is line two,\nThis is line three,\nAnd so on...")
f = File.new("testfile")
f.each { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one,\n"
# "2: This is line two,\n"
# "3: This is line three,\n"
# "4: A...
...読み取りバイト数に 10 を指定][ruby]{
IO.write("testfile", "This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is l...

絞り込み条件を変える

<< < ... 2 3 4 5 6 ... > >>