diff --git a/core/io.rbs b/core/io.rbs index 3817e3281..ffff2d5ba 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -694,7 +694,7 @@ class IO < Object # # ... # f.gets # won't cause Errno::EBADF # - def autoclose=: (boolish) -> untyped + def autoclose=: (boolish bool) -> boolish # - # Calls the block with each remaining line read from the stream; returns `self`. - # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO). - # - # With no arguments given, reads lines as determined by line separator `$/`: - # - # f = File.new('t.txt') - # f.each_line {|line| p line } - # f.each_line {|line| fail 'Cannot happen' } - # f.close - # - # Output: - # - # "First line\n" - # "Second line\n" - # "\n" - # "Fourth line\n" - # "Fifth line\n" - # - # With only string argument `sep` given, reads lines as determined by line - # separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator): - # - # f = File.new('t.txt') - # f.each_line('li') {|line| p line } - # f.close - # - # Output: - # - # "First li" - # "ne\nSecond li" - # "ne\n\nFourth li" - # "ne\nFifth li" - # "ne\n" - # - # The two special values for `sep` are honored: - # - # f = File.new('t.txt') - # # Get all into one string. - # f.each_line(nil) {|line| p line } - # f.close - # - # Output: - # - # "First line\nSecond line\n\nFourth line\nFifth line\n" - # - # f.rewind - # # Get paragraphs (up to two line separators). - # f.each_line('') {|line| p line } - # - # Output: - # - # "First line\nSecond line\n\n" - # "Fourth line\nFifth line\n" - # - # With only integer argument `limit` given, limits the number of bytes in each - # line; see [Line Limit](rdoc-ref:IO@Line+Limit): - # - # f = File.new('t.txt') - # f.each_line(8) {|line| p line } - # f.close - # - # Output: - # - # "First li" - # "ne\n" - # "Second l" - # "ine\n" - # "\n" - # "Fourth l" - # "ine\n" - # "Fifth li" - # "ne\n" - # - # With arguments `sep` and `limit` given, combines the two behaviors: - # - # * Calls with the next line as determined by line separator `sep`. - # * But returns no more bytes than are allowed by the limit. - # - # - # Optional keyword argument `chomp` specifies whether line separators are to be - # omitted: - # - # f = File.new('t.txt') - # f.each_line(chomp: true) {|line| p line } - # f.close - # - # Output: - # - # "First line" - # "Second line" - # "" - # "Fourth line" - # "Fifth line" - # - # Returns an Enumerator if no block is given. - # - # IO#each is an alias for IO#each_line. - # - def each: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self - | (?String sep, ?Integer limit) -> ::Enumerator[String, self] - # - # Returns the current position (in bytes) in `self` (see - # [Position](rdoc-ref:IO@Position)): - # - # f = File.open('t.txt') - # f.tell # => 0 - # f.gets # => "First line\n" - # f.tell # => 12 - # f.close - # - # Related: IO#pos=, IO#seek. - # - # IO#pos is an alias for IO#tell. - # - def pos: () -> Integer - # + # Returns the current position (in bytes) in `self` (see + # [Position](rdoc-ref:IO@Position)): + # + # f = File.open('t.txt') + # f.tell # => 0 + # f.gets # => "First line\n" + # f.tell # => 12 + # f.close + # + # Related: IO#pos=, IO#seek. + # + # IO#pos is an alias for IO#tell. + # + alias pos tell + # # Calls the block with each remaining line read from the stream; returns `self`. @@ -3314,9 +3202,115 @@ class IO < Object # # IO#each is an alias for IO#each_line. # - def each_line: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self + def each_line: (?String sep, ?Integer limit) { (String line) -> void } -> self | (?String sep, ?Integer limit) -> ::Enumerator[String, self] + # + # Calls the block with each remaining line read from the stream; returns `self`. + # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO). + # + # With no arguments given, reads lines as determined by line separator `$/`: + # + # f = File.new('t.txt') + # f.each_line {|line| p line } + # f.each_line {|line| fail 'Cannot happen' } + # f.close + # + # Output: + # + # "First line\n" + # "Second line\n" + # "\n" + # "Fourth line\n" + # "Fifth line\n" + # + # With only string argument `sep` given, reads lines as determined by line + # separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator): + # + # f = File.new('t.txt') + # f.each_line('li') {|line| p line } + # f.close + # + # Output: + # + # "First li" + # "ne\nSecond li" + # "ne\n\nFourth li" + # "ne\nFifth li" + # "ne\n" + # + # The two special values for `sep` are honored: + # + # f = File.new('t.txt') + # # Get all into one string. + # f.each_line(nil) {|line| p line } + # f.close + # + # Output: + # + # "First line\nSecond line\n\nFourth line\nFifth line\n" + # + # f.rewind + # # Get paragraphs (up to two line separators). + # f.each_line('') {|line| p line } + # + # Output: + # + # "First line\nSecond line\n\n" + # "Fourth line\nFifth line\n" + # + # With only integer argument `limit` given, limits the number of bytes in each + # line; see [Line Limit](rdoc-ref:IO@Line+Limit): + # + # f = File.new('t.txt') + # f.each_line(8) {|line| p line } + # f.close + # + # Output: + # + # "First li" + # "ne\n" + # "Second l" + # "ine\n" + # "\n" + # "Fourth l" + # "ine\n" + # "Fifth li" + # "ne\n" + # + # With arguments `sep` and `limit` given, combines the two behaviors: + # + # * Calls with the next line as determined by line separator `sep`. + # * But returns no more bytes than are allowed by the limit. + # + # + # Optional keyword argument `chomp` specifies whether line separators are to be + # omitted: + # + # f = File.new('t.txt') + # f.each_line(chomp: true) {|line| p line } + # f.close + # + # Output: + # + # "First line" + # "Second line" + # "" + # "Fourth line" + # "Fifth line" + # + # Returns an Enumerator if no block is given. + # + # IO#each is an alias for IO#each_line. + # + alias each each_line + # # Returns `true` if the stream is positioned at its end, `false` otherwise; see # [Position](rdoc-ref:IO@Position): @@ -3350,10 +3344,7 @@ class IO < Object # # IO#eof? is an alias for IO#eof. # - def eof?: () -> bool - - def lines: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self - | (?String sep, ?Integer limit) -> ::Enumerator[String, self] + alias eof? eof # # Returns the integer file descriptor for the stream: @@ -3366,7 +3357,7 @@ class IO < Object # # IO#to_i is an alias for IO#fileno. # - def to_i: () -> Integer + alias to_i fileno end IO::APPEND: Integer