るりまサーチ

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

別のキーワード

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

検索結果

<< < ... 6 7 8 9 10 > >>

ObjectSpace.#each_object {|object| ...} -> Integer (32.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) {|object| ...} -> Integer (32.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) {|line| ... } -> self (30.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) {|line| ... } -> self (30.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, limit, chomp: false) {|line| ... } -> self (30.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_line(limit, chomp: false) {|line| ... } -> self (30.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_line(rs = $/, chomp: false) {|line| ... } -> self (30.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_line(rs, limit, chomp: false) {|line| ... } -> self (30.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...

StopIteration#result -> object (30.0)

この例外オブジェクトを発生させる原因となったメソッド等の返り値を返します。

...返り値を返します。

object = Object.new
def object.each
yield :yield1
yield :yield2
:each_returned
end

enumerator
= object.to_enum

p enumerator.next #=> :yield1
p enumerator.next #=> :yield2

begin
enumerator
.next
rescue StopIteration => error
p error...

Pathname#ascend {|pathname| ... } -> nil (29.0)

self のパス名から親方向に辿っていったときの各パス名を新しい Pathname オ ブジェクトとして生成し、ブロックへの引数として渡して実行します。 ブロックを省略した場合は Enumerator を返します。

...場合は Enumerator を返します。

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

Pathname.new('/path/to/some/file.rb').ascend {|v| p v}
# => #<Pathname:/path/to/some/file.rb>
# #<Pathname:/path/to/some>
# #<Pathname:/path/to>
# #<Pathname:/path>
# #<Pathname:/>

Pathname.new('path/to/so...

絞り込み条件を変える

Pathname#descend {|pathname| ... } -> nil (29.0)

self のパス名の親から子供へと辿っていったときの各パス名を新しい Pathname オブジェクトとして生成し、ブロックへの引数として渡して実行しま す。 ブロックを省略した場合は Enumerator を返します。

...場合は Enumerator を返します。

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

Pathname.new('/path/to/some/file.rb').descend {|v| p v}
# => #<Pathname:/>
# #<Pathname:/path>
# #<Pathname:/path/to>
# #<Pathname:/path/to/some>
# #<Pathname:/path/to/some/file.rb>

Pathname.new('path/to/s...

Struct#filter {|i| ... } -> [object] (26.0)

構造体のメンバの値に対してブロックを評価した値が真であった要素を全て含 む配列を返します。真になる要素がひとつもなかった場合は空の配列を返しま す。

...つもなかった場合は空の配列を返しま
す。

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

//emlist[例][ruby]{
Lots = Struct.new(:a, :b, :c, :d, :e, :f)
l = Lots.new(11, 22, 33, 44, 55, 66)
l.select {|v| (v % 2).zero? } #=> [22, 44, 66]
//}

[注意] 本メソ...
...ッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

@see Enumerable#select...
<< < ... 6 7 8 9 10 > >>