D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
IO
/
Filename :
each-i.ri
back
Copy
U:RDoc::AnyMethod[iI" each:ETI"IO#each;TF:publico:RDoc::Markup::Document:@parts[+o:RDoc::Markup::Paragraph; [ I"DCalls the block with each remaining line read from the stream; ;TI"returns +self+. ;TI"/Does nothing if already at end-of-stream; ;TI"(See {Line IO}[rdoc-ref:IO@Line+IO].;To:RDoc::Markup::BlankLine o; ; [I"*With no arguments given, reads lines ;TI"1as determined by line separator <tt>$/</tt>:;T@o:RDoc::Markup::Verbatim; [ I"f = File.new('t.txt') ;TI""f.each_line {|line| p line } ;TI"0f.each_line {|line| fail 'Cannot happen' } ;TI" f.close ;T:@format0o; ; [I"Output:;T@o;; [ I""First line\n" ;TI""Second line\n" ;TI" "\n" ;TI""Fourth line\n" ;TI""Fifth line\n" ;T; 0o; ; [I",With only string argument +sep+ given, ;TI"8reads lines as determined by line separator +sep+; ;TI"6see {Line Separator}[rdoc-ref:IO@Line+Separator]:;T@o;; [I"f = File.new('t.txt') ;TI"(f.each_line('li') {|line| p line } ;TI" f.close ;T; 0o; ; [I"Output:;T@o;; [ I""First li" ;TI""ne\nSecond li" ;TI""ne\n\nFourth li" ;TI""ne\nFifth li" ;TI""ne\n" ;T; 0o; ; [I"2The two special values for +sep+ are honored:;T@o;; [ I"f = File.new('t.txt') ;TI" # Get all into one string. ;TI"'f.each_line(nil) {|line| p line } ;TI" f.close ;T; 0o; ; [I"Output:;T@o;; [ I"<"First line\nSecond line\n\nFourth line\nFifth line\n" ;TI" ;TI"f.rewind ;TI"3# Get paragraphs (up to two line separators). ;TI"&f.each_line('') {|line| p line } ;T; 0o; ; [I"Output:;T@o;; [I"#"First line\nSecond line\n\n" ;TI"!"Fourth line\nFifth line\n" ;T; 0o; ; [I"/With only integer argument +limit+ given, ;TI".limits the number of bytes in each line; ;TI".see {Line Limit}[rdoc-ref:IO@Line+Limit]:;T@o;; [I"f = File.new('t.txt') ;TI"%f.each_line(8) {|line| p line } ;TI" f.close ;T; 0o; ; [I"Output:;T@o;; [I""First li" ;TI""ne\n" ;TI""Second l" ;TI" "ine\n" ;TI" "\n" ;TI""Fourth l" ;TI" "ine\n" ;TI""Fifth li" ;TI""ne\n" ;T; 0o; ; [I"-With arguments +sep+ and +limit+ given, ;TI" combines the two behaviors ;TI"V(see {Line Separator and Line Limit}[rdoc-ref:IO@Line+Separator+and+Line+Limit]).;T@o; ; [I"IOptional keyword argument +chomp+ specifies whether line separators ;TI"are to be omitted:;T@o;; [I"f = File.new('t.txt') ;TI"/f.each_line(chomp: true) {|line| p line } ;TI" f.close ;T; 0o; ; [I"Output:;T@o;; [ I""First line" ;TI""Second line" ;TI""" ;TI""Fourth line" ;TI""Fifth line" ;T; 0o; ; [I"0Returns an Enumerator if no block is given.;T: @fileI" io.c;T:0@omit_headings_from_table_of_contents_below0I"�each_line(sep = $/, chomp: false) {|line| ... } -> self each_line(limit, chomp: false) {|line| ... } -> self each_line(sep, limit, chomp: false) {|line| ... } -> self each_line -> enumerator ;T0[[I"each_line;T@ I"(*args);T@�FI"IO;TcRDoc::NormalClass00