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#advance

advance(amount) → 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.

Example
buffer = IO::Buffer.for("test")
buffer.advance(1)
buffer.get_string # => "est"
See also #~ #and! #| #bit_count