# # IO streams for strings, with access similar to [IO](rdoc-ref:IO); see # [IO](rdoc-ref:IO). # # ### About the Examples # # Examples on this page assume that StringIO has been required: # # require 'stringio' # class StringIO # # Note that `mode` defaults to `'r'` if `string` is frozen. # # Returns a new StringIO instance formed from `string` and `mode`; see [Access # Modes](rdoc-ref:File@Access+Modes): # # strio = StringIO.new # => # # strio.close # # The instance should be closed when no longer needed. # # Related: StringIO.open (accepts block; closes automatically). # def initialize: (?String string, ?String? mode) -> void # # Note that `mode` defaults to `'r'` if `string` is frozen. # # Creates a new StringIO instance formed from `string` and `mode`; see [Access # Modes](rdoc-ref:File@Access+Modes). # # With no block, returns the new instance: # # strio = StringIO.open # => # # # With a block, calls the block with the new instance and returns the block's # value; closes the instance on block exit. # # StringIO.open {|strio| p strio } # # => # # # Related: StringIO.new. # def self.open: [U] (?String string, ?String? mode) { (StringIO arg) -> U } -> U def <<: (untyped arg0) -> self # # Sets the data mode in `self` to binary mode; see [Data # Mode](rdoc-ref:File@Data+Mode). # def binmode: () -> self # # Closes `self` for both reading and writing. # # Raises IOError if reading or writing is attempted. # # Related: StringIO#close_read, StringIO#close_write. # def close: () -> nil # # Closes `self` for reading; closed-write setting remains unchanged. # # Raises IOError if reading is attempted. # # Related: StringIO#close, StringIO#close_write. # def close_read: () -> nil # # Closes `self` for writing; closed-read setting remains unchanged. # # Raises IOError if writing is attempted. # # Related: StringIO#close, StringIO#close_read. # def close_write: () -> nil # # Returns `true` if `self` is closed for both reading and writing, `false` # otherwise. # def closed?: () -> bool # # Returns `true` if `self` is closed for reading, `false` otherwise. # def closed_read?: () -> bool # # Returns `true` if `self` is closed for writing, `false` otherwise. # def closed_write?: () -> bool # # Calls the block with each remaining line read from the stream; does nothing if # already at end-of-file; returns `self`. See [Line IO](rdoc-ref:IO@Line+IO). # # StringIO#each is an alias for StringIO#each_line. # def each: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self | (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self] # # With a block given, calls the block with each remaining byte in the stream; # see [Byte IO](rdoc-ref:IO@Byte+IO). # # With no block given, returns an enumerator. # def each_byte: () { (Integer arg0) -> untyped } -> self | () -> ::Enumerator[Integer, self] # # With a block given, calls the block with each remaining character in the # stream; see [Character IO](rdoc-ref:IO@Character+IO). # # With no block given, returns an enumerator. # def each_char: () { (String arg0) -> untyped } -> self | () -> ::Enumerator[String, self] # # With a block given, calls the block with each remaining codepoint in the # stream; see [Codepoint IO](rdoc-ref:IO@Codepoint+IO). # # With no block given, returns an enumerator. # def each_codepoint: () { (Integer arg0) -> untyped } -> self | () -> ::Enumerator[Integer, self] # # Returns `true` if positioned at end-of-stream, `false` otherwise; see # [Position](rdoc-ref:File@Position). # # Raises IOError if the stream is not opened for reading. # # StreamIO#eof is an alias for StreamIO#eof?. # def eof: () -> bool # # Raises NotImplementedError. # def fcntl: (Integer integer_cmd, String | Integer arg) -> Integer # # Returns `nil`. Just for compatibility to IO. # def fileno: () -> nil # # Returns an object itself. Just for compatibility to IO. # def flush: () -> self # # Returns 0. Just for compatibility to IO. # def fsync: () -> Integer? # # Reads and returns the next 8-bit byte from the stream; see [Byte # IO](rdoc-ref:IO@Byte+IO). # def getbyte: () -> Integer? # # Reads and returns the next character from the stream; see [Character # IO](rdoc-ref:IO@Character+IO). # def getc: () -> String? # # Reads and returns a line from the stream; assigns the return value to `$_`; # see [Line IO](rdoc-ref:IO@Line+IO). # def gets: (?String sep, ?Integer limit, ?chomp: boolish) -> String? # # Returns the Encoding of the internal string if conversion is specified. # Otherwise returns `nil`. # def internal_encoding: () -> Encoding # # Returns the Encoding object that represents the encoding of the file. If the # stream is write mode and no encoding is specified, returns `nil`. # def external_encoding: () -> Encoding # # Returns `false`. Just for compatibility to IO. # def isatty: () -> bool # # Returns the current line number in `self`; see [Line # Number](rdoc-ref:IO@Line+Number). # def lineno: () -> Integer # # Sets the current line number in `self` to the given `new_line_number`; see # [Line Number](rdoc-ref:IO@Line+Number). # def lineno=: (Integer arg0) -> Integer # # Returns `nil`. Just for compatibility to IO. # def pid: () -> nil # # Returns the current position (in bytes); see [Position](rdoc-ref:IO@Position). # # StringIO#tell is an alias for StringIO#pos. # def pos: () -> Integer # # Sets the current position (in bytes); see [Position](rdoc-ref:IO@Position). # def pos=: (Integer arg0) -> Integer def print: (*untyped arg0) -> nil def printf: (String format_string, *untyped arg0) -> nil # # See IO#putc. # def putc: (Numeric | String arg0) -> untyped def puts: (*untyped arg0) -> nil # # See IO#read. # def read: (?int? length, ?string outbuf) -> String? def read_nonblock: (int len, ?string buf) -> String def readbyte: () -> Integer def readchar: () -> String def readline: (?String sep, ?Integer limit) -> String # # See IO#readlines. # def readlines: (?String sep, ?Integer limit, ?chomp: boolish) -> ::Array[String] def readpartial: (int maxlen, ?string outbuf) -> String # # Reinitializes the stream with the given `other` (string or StringIO) and # `mode`; see IO.new: # # StringIO.open('foo') do |strio| # p strio.string # strio.reopen('bar') # p strio.string # other_strio = StringIO.new('baz') # strio.reopen(other_strio) # p strio.string # other_strio.close # end # # Output: # # "foo" # "bar" # "baz" # def reopen: (StringIO other) -> self | (String other, ?String mode_str) -> self # # Sets the current position and line number to zero; see # [Position](rdoc-ref:IO@Position) and [Line Number](rdoc-ref:IO@Line+Number). # def rewind: () -> Integer # # Sets the current position to the given integer `offset` (in bytes), with # respect to a given constant `whence`; see [Position](rdoc-ref:IO@Position). # def seek: (Integer amount, ?Integer whence) -> Integer # # Specify the encoding of the StringIO as *ext_enc*. Use the default external # encoding if *ext_enc* is nil. 2nd argument *int_enc* and optional hash *opt* # argument are ignored; they are for API compatibility to IO. # def set_encoding: (?String | Encoding ext_or_ext_int_enc) -> self | (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc) -> self # # Returns underlying string: # # StringIO.open('foo') do |strio| # p strio.string # strio.string = 'bar' # p strio.string # end # # Output: # # "foo" # "bar" # # Related: StringIO#string= (assigns the underlying string). # def string: () -> String # # Assigns the underlying string as `other_string`, and sets position to zero; # returns `other_string`: # # StringIO.open('foo') do |strio| # p strio.string # strio.string = 'bar' # p strio.string # end # # Output: # # "foo" # "bar" # # Related: StringIO#string (returns the underlying string). # def string=: (String str) -> String # # Returns the size of the buffer string. # def size: () -> Integer # # Returns `true`; implemented only for compatibility with other stream classes. # def sync: () -> bool # # Returns the argument unchanged. Just for compatibility to IO. # def sync=: (boolish) -> bool def sysread: (Integer maxlen, String outbuf) -> String def syswrite: (String arg0) -> Integer # # Returns the current position (in bytes); see [Position](rdoc-ref:IO@Position). # # StringIO#tell is an alias for StringIO#pos. # def tell: () -> Integer # # Truncates the buffer string to at most *integer* bytes. The stream must be # opened for writing. # def truncate: (Integer) -> 0 # # Returns `false`. Just for compatibility to IO. # def tty?: () -> bool # # Pushes back ("unshifts") an 8-bit byte onto the stream; see [Byte # IO](rdoc-ref:IO@Byte+IO). # def ungetbyte: (String | Integer arg0) -> nil # # Pushes back ("unshifts") a character or integer onto the stream; see # [Character IO](rdoc-ref:IO@Character+IO). # def ungetc: (String arg0) -> nil # # Appends the given string to the underlying buffer string. The stream must be # opened for writing. If the argument is not a string, it will be converted to # a string using `to_s`. Returns the number of bytes written. See IO#write. # def write: (*_ToS) -> Integer # This is a deprecated alias for #each_byte. # def bytes: () { (Integer arg0) -> untyped } -> self | () -> ::Enumerator[Integer, self] # This is a deprecated alias for #each_char. # def chars: () { (String arg0) -> untyped } -> self | () -> ::Enumerator[String, self] # This is a deprecated alias for #each_codepoint. # def codepoints: () { (Integer arg0) -> untyped } -> self | () -> ::Enumerator[Integer, self] # # Calls the block with each remaining line read from the stream; does nothing if # already at end-of-file; returns `self`. See [Line IO](rdoc-ref:IO@Line+IO). # # StringIO#each is an alias for StringIO#each_line. # def each_line: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self | (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self] # # Returns `true` if positioned at end-of-stream, `false` otherwise; see # [Position](rdoc-ref:File@Position). # # Raises IOError if the stream is not opened for reading. # # StreamIO#eof is an alias for StreamIO#eof?. # def eof?: () -> bool # This is a deprecated alias for #each_line. # def lines: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self | (?String sep, ?Integer limit) -> ::Enumerator[String, self] end