Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
IO::Buffer#valid?
static VALUE
rb_io_buffer_valid_p(VALUE self)
{
struct rb_io_buffer_view *buffer = get_io_buffer_view(self);
return RBOOL(io_buffer_validate(buffer));
}
A buffer without a source is always valid, including a null buffer. A source-backed buffer is valid when its offset and length fit within its source’s current size.
Relocating a source does not invalidate a source-backed buffer. Freeing, transferring, or shrinking the source can make it invalid; if the same source later grows to include the range again, the buffer becomes valid and refers to the current contents at its original offset.
An empty source-backed range at offset zero can be valid even when its source has no storage. valid?, null? and empty? describe distinct properties: a buffer can be valid, null, and empty at the same time.