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#puts

ios.puts(obj, ...) → nil

Writes the given object(s) to ios. Writes a newline after any that do not already end with a newline sequence. Returns nil.

The stream must be opened for writing. If called with an array argument, writes each element on a new line. Each given object that isn’t a string or array will be converted by calling its to_s method. If called without arguments, outputs a single newline.

Example
$stdout.puts("this", "is", ["a", "test"])

produces:

Example
this
is
a
test

Note that puts always uses newlines and is not affected by the output record separator ($\).

Ruby version changes

  1. 3.0
See also #putc #pwrite #printf #raw also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1