るりまサーチ

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

別のキーワード

  1. io popen
  2. io pipe
  3. io each
  4. io readlines
  5. io each_line

ライブラリ

クラス

キーワード

検索結果

IO.foreach(path, rs = $/, chomp: false) -> Enumerator (39198.0)

path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。

...ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO
.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}

//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO
.write("tes...
...line1,line2,line3")
IO
.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}

//emlist[例: 各行の末尾から "\n", "\r", または "\r\n" を取り除く(chomp = true)][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile", chomp...

IO.foreach(path, rs = $/, chomp: false) {|line| ... } -> nil (39198.0)

path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。

...ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO
.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}

//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO
.write("tes...
...line1,line2,line3")
IO
.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}

//emlist[例: 各行の末尾から "\n", "\r", または "\r\n" を取り除く(chomp = true)][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile", chomp...

IO.foreach(path, rs = $/) -> Enumerator (39174.0)

path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。

...ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO
.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}

//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO
.write("tes...
...tfile", "line1,line2,line3")
IO
.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}


@see $/...

IO.foreach(path, rs = $/) {|line| ... } -> nil (39174.0)

path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。

...ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO
.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}

//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO
.write("tes...
...tfile", "line1,line2,line3")
IO
.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}


@see $/...

IO (38420.0)

基本的な入出力機能のためのクラスです。

...基本的な入出力機能のためのクラスです。


File::Constants は、File から IO へ移動しました。

===[a:m17n] 多言語化と IO のエンコーディング

IO
オブジェクトはエンコーディングを持ちます。
エンコーディングの影響を受けるメ...
... IO のエンコーディングの影響をうけます。
詳しくは「io_encoding」を参照して下さい。
以下がテキスト読み込みメソッドです。

* IO.foreach
* IO.readlines
* IO#each_line
* IO#lines
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#rea...
...* IO#read(size)
* IO#read_nonblock
* IO#readpartial
* IO#sysread

また書き込みメソッド IO#write IO のエンコーディングの影響を受けます。
IO
のすべての書き込みメソッドは内部で IO#write を呼びますので、
書き込みメソッドはすべて IO...
... IO のエンコーディングの影響をうけます。
詳しくは「io_encoding」を参照して下さい。
以下がテキスト読み込みメソッドです。

* IO.foreach
* IO.readlines
* IO#each_line
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#readline
* IO#...

絞り込み条件を変える

Pathname#each_line(*args) -> Enumerator (104.0)

IO.foreach(self.to_s, *args, &block) と同じです。

...IO.foreach(self.to_s, *args, &block) と同じです。

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

IO
.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line
# => #<Enumerator: IO:foreach("testfile")>
//}

//emlist[例 ブロックを指定][ruby]{
require "pathname"

IO
.write("tes...
...指定][ruby]{
require "pathname"

IO
.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line(4) {|f| p f }

# => "line"
# => "1\n"
# => "line"
# => "2,\n"
# => "line"
# => "3\n"
//}

//emlist[例 sep を指定][ruby]{
require "pathname"

IO
.write("testfile", "line1\nline2,\nline3...
...\n")
Pathname("testfile").each_line(",") {|f| p f }

# => "line1\nline2,"
# => "\nline3\n"
//}

@see IO.foreach...

Pathname#each_line(*args) {|line| ... } -> nil (104.0)

IO.foreach(self.to_s, *args, &block) と同じです。

...IO.foreach(self.to_s, *args, &block) と同じです。

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

IO
.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line
# => #<Enumerator: IO:foreach("testfile")>
//}

//emlist[例 ブロックを指定][ruby]{
require "pathname"

IO
.write("tes...
...指定][ruby]{
require "pathname"

IO
.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line(4) {|f| p f }

# => "line"
# => "1\n"
# => "line"
# => "2,\n"
# => "line"
# => "3\n"
//}

//emlist[例 sep を指定][ruby]{
require "pathname"

IO
.write("testfile", "line1\nline2,\nline3...
...\n")
Pathname("testfile").each_line(",") {|f| p f }

# => "line1\nline2,"
# => "\nline3\n"
//}

@see IO.foreach...

CSV (42.0)

このクラスは CSV ファイルやデータに対する完全なインターフェイスを提供します。

...

=== 読み込み

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

csv_text = <<~CSV_TEXT
Ruby,1995
Rust,2010
CSV_TEXT

IO
.write "sample.csv", csv_text

# ファイルから一行ずつ
CSV.foreach("sample.csv") do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2010"]

# ファイルから一度に...
...<< %w{my data here} } # to $stderr
//}

=== CSV と文字エンコーディング (M17n or Multilingualization)

This new CSV parser is m17n savvy. The parser works in the Encoding of the IO
or String object being read from or written to. Your data is never transcoded
(unless you ask Ruby to tran...
...the target Encoding to avoid the translation.

It's also important to note that while all of CSV's core parser is now
Encoding agnostic, some features are not. For example, the built-in
converters will try to transcode data to UTF-8 before making conversions.
Again, you can provide custom converte...

NEWS for Ruby 2.6.0 (42.0)

NEWS for Ruby 2.6.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...れるときに、
例外の Exception#cause も表示されるようになりました。 8257

* フリップフロップが非推奨になりました。 5400

=== 組み込みクラスの更新

* Array
* 新規メソッド
* Array#union と Array#difference 14097
* 変更...
...プション
* :write_timeout キーワード引数が Net::HTTP.new に追加されました。 13396
* 新規メソッド
* Net::HTTP#write_timeout と Net::HTTP#write_timeout= が追加されました。 13396
* 新規定数
* Net::HTTPClientException が追加されて...
...渡すのは非推奨になる予定で、
今は警告が出ます。 14643

* File
* File.read, File.binread, File.write, File.binwrite,
File.foreach, File.readlines はパスがパイプ文字 '|' で始まっていても
外部コマンドを実行しなくなりました...