Skip to content
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

Constants
No documentation available