Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
IO::Buffer#advance
static VALUE
io_buffer_advance(VALUE self, VALUE amount)
{
rb_check_frozen(self);
size_t size = io_buffer_extract_amount(amount);
// Argument conversion may call Ruby code which freezes the receiver.
rb_check_frozen(self);
rb_io_buffer_advance(self, size);
return self;
}
Advances the beginning of a non-owning buffer view by amount bytes, reducing its size by the same amount. The backing memory is not moved or modified. The buffer must refer to memory managed elsewhere or be a slice; a buffer which owns its allocation cannot be advanced.
The source and allocation lock count are unchanged. Advancing is allowed while the bytes are read-only or the allocation is locked, because it only changes the view. If amount equals the current size, the buffer becomes an empty view at its previous end.
Raises ArgumentError if amount is negative or exceeds the current size, IO::Buffer::InvalidatedError if the view is invalid, or IO::Buffer::AccessError if the buffer owns its allocation. A frozen buffer cannot be advanced.
buffer = IO::Buffer.for("test") buffer.advance(1) buffer.get_string # => "est"