End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO#write
ios.write(string, ...) → integer
io.c
View on GitHub ↗
static VALUE
io_write_m(int argc, VALUE *argv, VALUE io)
{
if (argc != 1) {
return io_writev(argc, argv, io);
}
else {
VALUE str = argv[0];
return io_write(io, str, 0);
}
}
Writes the given strings to ios. The stream must be opened for writing. Arguments that are not a string will be converted to a string using to_s. Returns the number of bytes written in total.
Example
count = $stdout.write("This is", " a test\n") puts "That was #{count} bytes of data"
produces:
This is a test That was 15 bytes of data
Ruby version changes
-
3.0
-
IO#wait_readable,IO#wait_writable,IO#read,IO#writeand other related methods (e.g.IO#puts,IO#gets) may invoke the scheduler hook io_wait(io, events, timeout) in a non-blocking execution context. [Feature #16786]
-