D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
IO
/
Filename :
read-i.ri
back
Copy
U:RDoc::AnyMethod[iI" read:ETI"IO#read;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"HReads bytes from the stream; the stream must be opened for reading ;TI"6(see {Access Modes}[rdoc-ref:File@Access+Modes]):;To:RDoc::Markup::BlankLine o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"HIf +maxlen+ is +nil+, reads all bytes using the stream's data mode.;To;;0; [o; ; [I"9Otherwise reads up to +maxlen+ bytes in binary mode.;T@o; ; [I"FReturns a string (either a new string or the given +out_string+) ;TI" containing the bytes read. ;TI"JThe encoding of the string depends on both +maxLen+ and +out_string+:;T@o;; ;;[o;;0; [o; ; [I"9+maxlen+ is +nil+: uses internal encoding of +self+ ;TI"4(regardless of whether +out_string+ was given).;To;;0; [o; ; [I"+maxlen+ not +nil+:;T@o;; ;;[o;;0; [o; ; [I"?+out_string+ given: encoding of +out_string+ not modified.;To;;0; [o; ; [I"0+out_string+ not given: ASCII-8BIT is used.;T@o; ; [I")<b>Without Argument +out_string+</b>;T@o; ; [I",When argument +out_string+ is omitted, ;TI"(the returned value is a new string:;T@o:RDoc::Markup::Verbatim; [ I"f = File.new('t.txt') ;TI"f.read ;TI"A# => "First line\nSecond line\n\nFourth line\nFifth line\n" ;TI"f.rewind ;TI"<f.read(30) # => "First line\r\nSecond line\r\n\r\nFou" ;TI"2f.read(30) # => "rth line\r\nFifth line\r\n" ;TI"f.read(30) # => nil ;TI" f.close ;T:@format0o; ; [I"2If +maxlen+ is zero, returns an empty string.;T@o; ; [I"'<b> With Argument +out_string+</b>;T@o; ; [I"*When argument +out_string+ is given, ;TI"Cthe returned value is +out_string+, whose content is replaced:;T@o;; [I"f = File.new('t.txt') ;TI"s = 'foo' # => "foo" ;TI"Pf.read(nil, s) # => "First line\nSecond line\n\nFourth line\nFifth line\n" ;TI"Ps # => "First line\nSecond line\n\nFourth line\nFifth line\n" ;TI"f.rewind ;TI"s = 'bar' ;TI"@f.read(30, s) # => "First line\r\nSecond line\r\n\r\nFou" ;TI"@s # => "First line\r\nSecond line\r\n\r\nFou" ;TI"s = 'baz' ;TI"6f.read(30, s) # => "rth line\r\nFifth line\r\n" ;TI"6s # => "rth line\r\nFifth line\r\n" ;TI"s = 'bat' ;TI"f.read(30, s) # => nil ;TI"s # => "" ;TI" f.close ;T;0o; ; [I"CNote that this method behaves like the fread() function in C. ;TI"GThis means it retries to invoke read(2) system calls to read data ;TI".with the specified maxlen (or until EOF).;T@o; ; [I"LThis behavior is preserved even if the stream is in non-blocking mode. ;TI"E(This method is non-blocking-flag insensitive as other methods.);T@o; ; [I"AIf you need the behavior like a single read(2) system call, ;TI"9consider #readpartial, #read_nonblock, and #sysread.;T@o; ; [I"Related: IO#write.;T: @fileI" io.c;T:0@omit_headings_from_table_of_contents_below0I"Lread(maxlen = nil, out_string = nil) -> new_string, out_string, or nil ;T0[ I"(p1 = v1, p2 = v2);T@vFI"IO;TcRDoc::NormalClass00