On this page
End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class · Ruby 3.0
StringIO
< Object
include Enumerable
include IO::generic_readable
include IO::generic_writable
49 instance methods
2 class methods
Pseudo I/O on String object, with interface corresponding to IO.
Commonly used to simulate $stdio or $stderr
Examples
Example
require 'stringio' # Writing stream emulation io = StringIO.new io.puts "Hello World" io.string #=> "Hello World\n" # Reading stream emulation io = StringIO.new "first\nsecond\nlast\n" io.getc #=> "f" io.gets #=> "irst\n" io.read #=> "second\nlast\n"
Class methods 2
Instance methods 49
#binmode
#close
#closed?
#closed_read?
#closed_write?
#close_read
#close_write
#each
#each_byte
#each_char
#each_codepoint
#each_line
#eof
#eof?
#external_encoding
#fcntl
#fileno
#flush
#fsync
#getbyte
#getc
#gets
#internal_encoding
#isatty
#length
#lineno
#lineno=
#pid
#pos
#pos=
#putc
#read
#readlines
#reopen
#rewind
#seek
#set_encoding
#set_encoding_by_bom
#size
#string
#string=
#sync
#sync=
#tell
#truncate
#tty?
#ungetbyte
#ungetc
#write
Constants
No documentation available