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");
}
RBASIC(self)->flags &= ~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?.