Skip to content

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

instance method

IO#write

(*::_ToS string) -> ::Integer
write(*objects) → integer

Writes each of the given objects to self, which must be opened for writing (see Access Modes); returns the total number bytes written; each of objects that is not a string is converted via method to_s:

Example
$stdout.write('Hello', ', ', 'World!', "\n") # => 14
$stdout.write('foo', :bar, 2, "\n")          # => 8

Output:

Hello, World!
foobar2

Related: IO#read.

Ruby version changes

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