Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

IO::Buffer#write

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

Write at least length bytes from the buffer starting at offset, into the io. If an error occurs, return -errno.

If length is not given or nil, it defaults to the size of the buffer minus the offset, i.e. the entire buffer.

If length is zero, exactly one write operation will occur.

If offset is not given, it defaults to zero, i.e. the beginning of the buffer.

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

This leads to 123 being written into output.txt

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