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