Skip to content
instance method

Kernel#printf

() -> nil
(::String fmt, *untyped args) -> nil
(::_Writer io, ::string fmt, *untyped args) -> nil
printf(format_string, *objects) → nil
printf(io, format_string, *objects) → nil

Equivalent to:

Example
io.write(sprintf(format_string, *objects))

For details on format_string, see Format Specifications.

With the single argument format_string, formats objects into the string, then writes the formatted string to $stdout:

Example
printf('%4.4d %10s %2.2f', 24, 24, 24.0)

Output (on $stdout):

0024         24 24.00#

With arguments io and format_string, formats objects into the string, then writes the formatted string to io:

Example
printf($stderr, '%4.4d %10s %2.2f', 24, 24, 24.0)

Output (on $stderr):

0024         24 24.00# => nil

With no arguments, does nothing.

See also #print #proc #pretty_inspect #putc also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0