D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
IO
/
Filename :
gets-i.ri
back
Copy
U:RDoc::AnyMethod[iI" gets:ETI"IO#gets;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"/Reads and returns a line from the stream; ;TI".assigns the return value to <tt>$_</tt>. ;TI"(See {Line IO}[rdoc-ref:IO@Line+IO].;To:RDoc::Markup::BlankLine o; ; [I"4With no arguments given, returns the next line ;TI"Cas determined by line separator <tt>$/</tt>, or +nil+ if none:;T@o:RDoc::Markup::Verbatim; [ I"f = File.open('t.txt') ;TI" f.gets # => "First line\n" ;TI" $_ # => "First line\n" ;TI"f.gets # => "\n" ;TI"!f.gets # => "Fourth line\n" ;TI" f.gets # => "Fifth line\n" ;TI"f.gets # => nil ;TI" f.close ;T:@format0o; ; [ I",With only string argument +sep+ given, ;TI"Breturns the next line as determined by line separator +sep+, ;TI"or +nil+ if none; ;TI"6see {Line Separator}[rdoc-ref:IO@Line+Separator]:;T@o;; [I"f = File.new('t.txt') ;TI""f.gets('l') # => "First l" ;TI")f.gets('li') # => "ine\nSecond li" ;TI"+f.gets('lin') # => "ne\n\nFourth lin" ;TI"f.gets # => "e\n" ;TI" f.close ;T; 0o; ; [I"2The two special values for +sep+ are honored:;T@o;; [I"f = File.new('t.txt') ;TI"# Get all. ;TI"Mf.gets(nil) # => "First line\nSecond line\n\nFourth line\nFifth line\n" ;TI"f.rewind ;TI"2# Get paragraph (up to two line separators). ;TI"4f.gets('') # => "First line\nSecond line\n\n" ;TI" f.close ;T; 0o; ; [I"/With only integer argument +limit+ given, ;TI"-limits the number of bytes in the line; ;TI".see {Line Limit}[rdoc-ref:IO@Line+Limit]:;T@o;; [ I"# No more than one line. ;TI"<File.open('t.txt') {|f| f.gets(10) } # => "First line" ;TI">File.open('t.txt') {|f| f.gets(11) } # => "First line\n" ;TI">File.open('t.txt') {|f| f.gets(12) } # => "First 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"IOptional keyword argument +chomp+ specifies whether line separators ;TI"are to be omitted:;T@o;; [I"f = File.open('t.txt') ;TI"# Chomp the lines. ;TI"+f.gets(chomp: true) # => "First line" ;TI",f.gets(chomp: true) # => "Second line" ;TI"!f.gets(chomp: true) # => "" ;TI",f.gets(chomp: true) # => "Fourth line" ;TI"+f.gets(chomp: true) # => "Fifth line" ;TI""f.gets(chomp: true) # => nil ;TI"f.close;T; 0: @fileI" io.c;T:0@omit_headings_from_table_of_contents_below0I"�gets(sep = $/, chomp: false) -> string or nil gets(limit, chomp: false) -> string or nil gets(sep, limit, chomp: false) -> string or nil ;T0[ I"(*args);T@XFI"IO;TcRDoc::NormalClass00