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
io_buffer.c
View on GitHub ↗
static VALUE
io_buffer_write(int argc, VALUE *argv, VALUE self)
{
rb_check_arity(argc, 1, 3);
VALUE io = argv[0];
size_t offset, length;
io_buffer_extract_offset_length(self, argc-1, argv+1, &offset, &length);
return rb_io_buffer_write(self, io, offset, length);
}
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