Method: StringIO#reopen

Defined in:
ext/stringio/stringio.c

#reopen(other, mode = 'r+') ⇒ self

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"

Returns:

  • (self)


718
719
720
721
722
723
724
725
726
# File 'ext/stringio/stringio.c', line 718

static VALUE
strio_reopen(int argc, VALUE *argv, VALUE self)
{
    rb_io_taint_check(self);
    if (argc == 1 && !RB_TYPE_P(*argv, T_STRING)) {
  return strio_copy(self, *argv);
    }
    return strio_init(argc, argv, StringIO(self), self);
}