Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
IO::Buffer#source
static VALUE
io_buffer_source(VALUE self)
{
return get_io_buffer_view(self)->source;
}
Returns the object backing this view, or nil for a source-less buffer. A slice’s source is the buffer on which slice was called, including when that buffer is itself a slice. The source is retained while the view lives.
root = IO::Buffer.new(8) parent = root.slice(1, 6) child = parent.slice(1, 2) child.source.equal?(parent) # => true parent.source.equal?(root) # => true root.source # => nil
For a String-backed buffer the source is its backing String. Without a block, IO::Buffer.for may use a frozen internal copy rather than the original String. A source-less buffer may own or borrow its memory; a nil source does not imply allocation ownership.
An invalid slice still retains and returns its source. Storage#free or Storage#transfer clears that Storage object’s source; Slice has neither operation. There is no source setter.