Skip to content
instance method

StringIO#reopen

(::StringIO other) -> self
(::String other, ?::String mode_str) -> self
reopen(other, mode = 'r+') → self

Reinitializes the stream with the given other (string or StringIO) and mode; see IO.new:

Example
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:

Example
"foo"
"bar"
"baz"
See also #readlines #rewind #read #seek also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0