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#null?

() -> bool
null? → true or false

Returns whether the buffer has no recorded base address.

A buffer is null if it was freed with free, transferred with transfer, or was never allocated in the first place. A zero-sized buffer or slice may have a non-null address, so null? and empty? are distinct properties.

Example
buffer = IO::Buffer.new(0)
buffer.null? #=> true

buffer = IO::Buffer.new(4)
buffer.null? #=> false
buffer.free
buffer.null? #=> true
See also #not! #or! #locked? #pread also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1