るりまサーチ (Ruby 2.6.0)

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

別のキーワード

  1. _builtin each
  2. _builtin each_line
  3. prime each
  4. tsort tsort_each

ライブラリ

検索結果

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