End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Kernel#print
static VALUE
rb_f_print(int argc, const VALUE *argv, VALUE _)
{
rb_io_print(argc, argv, rb_ractor_stdout());
return Qnil;
}
Equivalent to $stdout.print(*objects), this method is the straightforward way to write to $stdout.
Writes the given objects to $stdout; returns nil. Appends the output record separator $OUTPUT_RECORD_SEPARATOR $\), if it is not nil.
With argument objects given, for each object:
-
Converts via its method
to_sif not a string. -
Writes to
stdout. -
If not the last object, writes the output field separator
$OUTPUT_FIELD_SEPARATOR($,if it is notnil.
With default separators:
objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero'] $OUTPUT_RECORD_SEPARATOR $OUTPUT_FIELD_SEPARATOR print(*objects)
Output:
nil nil 00.00/10+0izerozero
With specified separators:
$OUTPUT_RECORD_SEPARATOR = "\n" $OUTPUT_FIELD_SEPARATOR = ',' print(*objects)
Output:
0,0.0,0/1,0+0i,zero,zero
With no argument given, writes the content of $_ (which is usually the most recent user input):
gets # Sets $_ to the most recent user input. print # Prints $_.