Class

StringIO

Inheritance
< Object
Included Modules
Enumerable

Pseudo I/O on String object.

Methods

Class

Visibility Signature
public new (string="")
public new (...)
public open (...)

Instance

Visibility Signature
public << (p1)
public binmode ()
public bytes ()
public chars ()
public close ()
public close_read ()
public close_write ()
public closed? ()
public closed_read? ()
public closed_write? ()
public each (...)
public each_byte ()
public each_char ()
public each_line (...)
public eof ()
public eof ()
public eof? ()
public eof? ()
public fcntl (...)
public fileno ()
public flush ()
public fsync ()
public getbyte ()
public getc ()
public gets (...)
public isatty ()
public length ()
public lineno ()
public lineno= (p1)
public lines (...)
public path ()
public pid ()
public pos ()
public pos ()
public pos= (p1)
public print (...)
public printf (...)
public putc (p1)
public puts (...)
public read (...)
public readbyte ()
public readchar ()
public readline (rs=$/)
public readline (...)
public readlines (...)
public reopen (...)
public rewind ()
public rewind ()
public seek (offset,whence)
public seek (...)
public size ()
public string ()
public string= (p1)
public sync ()
public sync= (p1)
public sysread (...)
public syswrite (p1)
public tell ()
public truncate (p1)
public tty? ()
public ungetc (p1)
public write (p1)

Class Method Detail

new(string="")

StringIO.new(string=""[, mode])

Creates new StringIO instance from with string and mode.

StringIO.open(string=""[, mode]) {|strio| ...}

Equivalent to StringIO.new except that when it is called with a block, it yields with the new instance and closes it, and returns the result which returned from the block.

Instance Method Detail

strio << obj → strio

See IO#<<.

strio.binmode → true

Returns strio itself. Just for compatibility to IO.

strio.each_byte {|byte| block } → strio

strio.each_char {|char| block } → strio

strio.close → nil

Closes strio. The strio is unavailable for any further data operations; an IOError is raised if such an attempt is made.

strio.close_read → nil

Closes the read end of a StringIO. Will raise an IOError if the strio is not readable.

strio.close_write → nil

Closes the write end of a StringIO. Will raise an IOError if the strio is not writeable.

strio.closed? → true or false

Returns true if strio is completely closed, false otherwise.

strio.closed_read? → true or false

Returns true if strio is not readable, false otherwise.

strio.closed_write? → true or false

Returns true if strio is not writable, false otherwise.

strio.each(sep_string=$/) {|line| block } → strio
strio.each_line(sep_string=$/) {|line| block } → strio

See IO#each.

strio.each_byte {|byte| block } → strio

strio.each_char {|char| block } → strio

strio.each(sep_string=$/) {|line| block } → strio
strio.each_line(sep_string=$/) {|line| block } → strio

See IO#each.

eof()

strio.eof → true or false
strio.eof? → true or false

Returns true if strio is at end of file. The stringio must be opened for reading or an IOError will be raised.

strio.eof → true or false
strio.eof? → true or false

Returns true if strio is at end of file. The stringio must be opened for reading or an IOError will be raised.

eof?()

Alias for eof

strio.fcntl

strio.fileno → nil

Returns nil. Just for compatibility to IO.

strio.flush → strio

Returns strio itself. Just for compatibility to IO.

strio.fsync → 0

Returns 0. Just for compatibility to IO.

strio.getc → fixnum or nil

See IO#getc.

strio.getc → fixnum or nil

See IO#getc.

strio.gets(sep_string=$/) → string or nil

See IO#gets.

strio.isatty → nil
strio.tty? → nil

Returns false. Just for compatibility to IO.

strio.size → integer

Returns the size of the buffer string.

strio.lineno → integer

Returns the current line number in strio. The stringio must be opened for reading. lineno counts the number of times gets is called, rather than the number of newlines encountered. The two values will differ if gets is called with a separator other than newline. See also the $. variable.

strio.lineno = integer → integer

Manually sets the current line number to the given value. $. is updated only on the next read.

strio.each(sep_string=$/) {|line| block } → strio
strio.each_line(sep_string=$/) {|line| block } → strio

See IO#each.

strio.path → nil

Returns nil. Just for compatibility to IO.

strio.pid → nil

Returns nil. Just for compatibility to IO.

pos()

strio.pos → integer
strio.tell → integer

Returns the current offset (in bytes) of strio.

strio.pos = integer → integer

Seeks to the given position (in bytes) in strio.

strio.print() → nil
strio.print(obj, ...) → nil

See IO#print.

strio.printf(format_string [, obj, ...] ) → nil

See IO#printf.

strio.putc(obj) → obj

See IO#putc.

strio.puts(obj, ...) → nil

See IO#puts.

strio.read([length [, buffer]]) → string, buffer, or nil

See IO#read.

strio.readchar → fixnum

strio.readchar → fixnum

readline(rs=$/)

strio.readline(sep_string=$/) → string

strio.readlines(sep_string=$/) → array

strio.reopen(other_StrIO) → strio
strio.reopen(string, mode) → strio

Reinitializes strio with the given other_StrIO or string and mode (see StringIO#new).

strio.rewind → 0

Positions strio to the beginning of input, resetting lineno to zero.

rewind()

seek(offset,whence)

strio.seek(amount, whence=SEEK_SET) → 0

Seeks to a given offset amount in the stream according to the value of whence (see IO#seek).

strio.size → integer

Returns the size of the buffer string.

strio.string → string

Returns underlying String object, the subject of IO.

strio.string = string → string

Changes underlying String object, the subject of IO.

strio.sync → true

Returns true always.

strio.sync = boolean → boolean

Returns the argument unchanged. Just for compatibility to IO.

strio.sysread(integer[, outbuf]) → string

Similar to read, but raises EOFError at end of string instead of returning nil, as well as IO#sysread does.

strio.write(string) → integer
strio.syswrite(string) → integer

Appends the given string to the underlying buffer string of strio. 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.

strio.pos → integer
strio.tell → integer

Returns the current offset (in bytes) of strio.

strio.truncate(integer) → 0

Truncates the buffer string to at most integer bytes. The strio must be opened for writing.

strio.isatty → nil
strio.tty? → nil

Returns false. Just for compatibility to IO.

strio.ungetc(integer) → nil

Pushes back one character (passed as a parameter) onto strio such that a subsequent buffered read will return it. Pushing back behind the beginning of the buffer string is not possible. Nothing will be done if such an attempt is made. In other case, there is no limitation for multiple pushbacks.

strio.write(string) → integer
strio.syswrite(string) → integer

Appends the given string to the underlying buffer string of strio. 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.