るりまサーチ

最速Rubyリファレンスマニュアル検索!
5470件ヒット [1-100件を表示] (0.081秒)
トップページ > クエリ:|[x] > クエリ:-[x] > クエリ:each[x]

別のキーワード

  1. _builtin |
  2. set |
  3. ipaddr |
  4. integer |
  5. array |

ライブラリ

モジュール

オブジェクト

キーワード

検索結果

<< 1 2 3 ... > >>

Prime#each(upper_bound = nil, generator = EratosthenesGenerator.new) {|prime| ... } -> object (18399.0)

全ての素数を順番に与えられたブロックに渡して評価します。

...require 'prime'
Prime.each(6){|prime| prime } # => 5
Prime.each(7){|prime| prime } # => 7
Prime.each(10){|prime| prime } # => 7
Prime.each(11){|prime| prime } # => 11
//}

//emlist[例: 30以下の双子素数][ruby]{
require 'prime'
Prime.each(30).each_cons(2).select{|p,r| r-p == 2}
#=> [[3, 5],...
...ない数列が発生します。
//emlist[例][ruby]{
require 'prime'
Prime.each(50, Prime::Generator23.new) do |n|
p n #=> [2, 3, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35, 37, 41, 43, 47, 49]
end
//}

@see Prime.each, Prime::EratosthenesGenerator, Prime::TrialDivisionGenerator, Prime::Generator2...

Zlib::GzipReader#each(rs = $/) {|line| ... } -> self (18392.0)

IO クラスの同名メソッドIO#each, IO#each_lineと同じです。

...IO クラスの同名メソッドIO#each, IO#each_lineと同じです。

但し、gzip ファイル中に
エラーがあった場合 Zlib::Error 例外や
Zlib::GzipFile::Error 例外が発生します。

gzip ファイルのフッターの処理に注意して下さい。
gzip ファイルの...
...

require 'zlib'

=begin
# hoge.gz がない場合は下記で作成できる。
Zlib::GzipWriter.open('hoge.gz') { |gz|
gz.puts 'hoge'
gz.puts 'fuga'
}
=end

Zlib::GzipReader.open('hoge.gz') { |gz|
gz.each { |line|
puts line
}
}

@see IO#each, IO#each_line...

IO#each(limit, chomp: false) {|line| ... } -> self (18372.0)

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

...引数なし][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: And so on..."
//}
//eml...
...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 li"
# "3: ne three,"
# "3: A...
...p = true][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(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/...

IO#each(rs = $/, chomp: false) {|line| ... } -> self (18372.0)

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

...引数なし][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: And so on..."
//}
//eml...
...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 li"
# "3: ne three,"
# "3: A...
...p = true][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(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/...

IO#each(rs, limit, chomp: false) {|line| ... } -> self (18372.0)

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

...引数なし][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: And so on..."
//}
//eml...
...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 li"
# "3: ne three,"
# "3: A...
...p = true][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(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/...

絞り込み条件を変える

Hash#each {|key, value| ... } -> self (18366.0)

ハッシュのキーと値を引数としてブロックを評価します。

...

each
_pair は each のエイリアスです。

//emlist[例][ruby]{
{:a=>1, :b=>2}.each {|a| p a}
#=> [:a, 1]
# [:b, 2]

{:a=>1, :b=>2}.each {|k, v| p [k, v]}
#=> [:a, 1]
# [:b, 2]

p({:a=>1, :b=>2}.each_pair) # => #<Enumerator: {:a=>1, :b=>2}:each_pair>
//}

@see Hash#each_key,Hash#each_val...

REXML::Elements#each(xpath = nil) {|element| ... } -> [REXML::Elements] (18356.0)

全ての子要素に対しブロックを呼び出します。

...

xpath を指定した場合には、その XPath 文字列に
マッチする要素に対しブロックを呼び出します。

REXML::XPath.each などとは異なり、要素以外の
テキストノードなどはすべて無視されることに注意してください。

@param xpath XP...
...に渡される
doc.root.elements.each {|e|p e}
# <b/>, <b/> がブロックに渡される
doc.root.elements.each('b') {|e|p e} #-> Yields b, b elements
# <b/>,<c/>,<d/>,<b/>,<c/>,<d/> がブロックに渡される
doc.root.elements.each('child::node()') {|e|p e}
# <b/>,<c/>,<d/>,"sean",<b/>,<c/...
...>,<d/> がブロックに渡される
REXML::XPath.each(doc.root, 'child::node()'){|node| p node }
//}...

IO#each(limit) {|line| ... } -> self (18354.0)

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

...引数なし][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: And so on..."
//}
//eml...
...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 li"
# "3: ne three,"
# "3: A...

IO#each(rs = $/) {|line| ... } -> self (18354.0)

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

...引数なし][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: And so on..."
//}
//eml...
...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 li"
# "3: ne three,"
# "3: A...

IO#each(rs, limit) {|line| ... } -> self (18354.0)

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

...引数なし][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: And so on..."
//}
//eml...
...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 li"
# "3: ne three,"
# "3: A...

絞り込み条件を変える

CSV::Row#each {|header, field| ... } -> self (18350.0)

与えられたブロックにヘッダとフィールドの組を渡して評価します。

...ドチェーンのために自身を返します。

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

row = CSV::Row.new(["header1", "header2", "header3", "header4"], [1, 2, 3, 4])
row.each { |header, field| puts "#{header} - #{field}" }

# => header1 - 1
# => header2 - 2
# => header3 - 3
# => header4 - 4
//}...

ARGF.class#each(rs = $/) { |line| ... } -> self (18346.0)

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

...フモード)。

@param limit 各行の最大の読み込みバイト数

例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示

ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end

@see IO#each, IO#each_line...

ARGF.class#each(rs = $/, limit) { |line| ... } -> self (18346.0)

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

...フモード)。

@param limit 各行の最大の読み込みバイト数

例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示

ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end

@see IO#each, IO#each_line...
<< 1 2 3 ... > >>