るりまサーチ (Ruby 2.6.0)

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

別のキーワード

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

ライブラリ

検索結果

IO.foreach(path, rs = $/, chomp: false) -> Enumerator (117544.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("t...
...", "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", c...

IO.foreach(path, rs = $/, chomp: false) {|line| ... } -> nil (117544.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("t...
...", "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", c...