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

(untyped, untyped) -> untyped
write(io, [offset, [length]]) → written length or -errno

Perform one write operation of at most length bytes to io from the buffer starting at offset. A short write is a normal result. If an error occurs, return -errno.

If offset is not given, it defaults to zero, i.e. the beginning of the buffer. If length is not given, it defaults to the size of the buffer minus the offset. A zero length is a no-op.

Example
out = File.open('output.txt', 'wb')
IO::Buffer.for('1234567').write(out, 0, 3)

This leads to 123 being written into output.txt

See also #values #xor! #valid? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1