each(rs = $/, chomp: false) {|line| ... } -> self
[permalink][rdoc]each(limit, chomp: false) {|line| ... } -> self
each(rs, limit, chomp: false) {|line| ... } -> self
each(rs = $/, chomp: false) -> Enumerator
each(limit, chomp: false) -> Enumerator
each(rs, limit, chomp: false) -> Enumerator
each_line(rs = $/, chomp: false) {|line| ... } -> self
each_line(limit, chomp: false) {|line| ... } -> self
each_line(rs, limit, chomp: false) {|line| ... } -> self
each_line(rs = $/, chomp: false) -> Enumerator
each_line(limit, chomp: false) -> Enumerator
each_line(rs, limit, chomp: false) -> Enumerator
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として与えられたブロックを実行します。
ブロックが与えられなかった場合は、自身から生成した Enumerator オブジェクトを返します。
テキスト読み込みメソッドとして動作します。
limit で最大読み込みバイト数を指定します。ただしマルチバイト文字が途中で切れないように余分に読み込む場合があります。
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..."
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: And so on."
# "4: .."
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..."