Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO::Buffer#valid?

() -> bool
valid? → true or false

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.

See also #to_s #values #source #write also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1