Skip to content

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

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

  1. 3.0
See also .write #winsize= #write_nonblock #winsize also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1