D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
IO
/
Filename :
foreach-c.ri
back
Copy
U:RDoc::AnyMethod[iI"foreach:ETI"IO::foreach;TT:publico:RDoc::Markup::Document:@parts[*o:RDoc::Markup::Paragraph; [I"DCalls the block with each successive line read from the stream.;To:RDoc::Markup::BlankLine o; ; [I"=When called from class \IO (but not subclasses of \IO), ;TI"Xthis method has potential security vulnerabilities if called with untrusted input; ;TI">see {Command Injection}[rdoc-ref:command_injection.rdoc].;T@o; ; [I"DThe first argument must be a string that is the path to a file.;T@o; ; [I"VWith only argument +path+ given, parses lines from the file at the given +path+, ;TI"2as determined by the default line separator, ;TI"3and calls the block with each successive line:;T@o:RDoc::Markup::Verbatim; [I",File.foreach('t.txt') {|line| p line } ;T:@format0o; ; [I"Output: the same as above.;T@o; ; [I"LFor both forms, command and path, the remaining arguments are the same.;T@o; ; [I"RWith argument +sep+ given, parses lines as determined by that line separator ;TI"8(see {Line Separator}[rdoc-ref:IO@Line+Separator]):;T@o;; [I"2File.foreach('t.txt', 'li') {|line| p line } ;T; 0o; ; [I"Output:;T@o;; [ I""First li" ;TI""ne\nSecond li" ;TI""ne\n\nThird li" ;TI""ne\nFourth li" ;TI""ne\n" ;T; 0o; ; [I"Each paragraph:;T@o;; [I":File.foreach('t.txt', '') {|paragraph| p paragraph } ;T; 0o; ; [I"Output:;T@o;; [I"#"First line\nSecond line\n\n" ;TI"!"Third line\nFourth line\n" ;T; 0o; ; [I"LWith argument +limit+ given, parses lines as determined by the default ;TI"4line separator and the given line-length limit ;TI"a(see {Line Separator}[rdoc-ref:IO@Line+Separator] and {Line Limit}[rdoc-ref:IO@Line+Limit]):;T@o;; [I"/File.foreach('t.txt', 7) {|line| p line } ;T; 0o; ; [I"Output:;T@o;; [I""First l" ;TI" "ine\n" ;TI""Second " ;TI""line\n" ;TI" "\n" ;TI""Third l" ;TI" "ine\n" ;TI""Fourth l" ;TI""line\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"/Optional keyword arguments +opts+ specify:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I".{Open Options}[rdoc-ref:IO@Open+Options].;To;;0; [o; ; [I"B{Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].;To;;0; [o; ; [I"){Line Options}[rdoc-ref:IO@Line+IO].;T@o; ; [I"0Returns an Enumerator if no block is given.;T: @fileI" io.c;T:0@omit_headings_from_table_of_contents_below0I" IO.foreach(path, sep = $/, **opts) {|line| block } -> nil IO.foreach(path, limit, **opts) {|line| block } -> nil IO.foreach(path, sep, limit, **opts) {|line| block } -> nil IO.foreach(...) -> an_enumerator ;T0[ I"$(p1, p2 = v2, p3 = v3, p4 = {});T@uFI"IO;TcRDoc::NormalClass00