Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
StringIO#close_write
() -> nil
close_write → nil
ext/stringio/stringio.c
View on GitHub ↗
static VALUE
strio_close_write(VALUE self)
{
struct StringIO *ptr = StringIO(self);
if (!(ptr->flags & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "closing non-duplex IO for writing");
}
RB_FL_UNSET_RAW(self, STRIO_WRITABLE);
return Qnil;
}
Closes self for writing; closed-read setting remains unchanged; returns nil:
Example
strio = StringIO.new strio.closed_write? # => false strio.close_write # => nil strio.closed_write? # => true strio.closed_read? # => false strio.write('foo') # Raises IOError: not opened for writing
Related: StringIO#close, StringIO#close_read, StringIO#closed_write?.