Method: Kernel#print
- Defined in:
- io.c
#print(*objects) ⇒ nil
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_s
if 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 $_.
8803 8804 8805 8806 8807 8808 |
# File 'io.c', line 8803 static VALUE rb_f_print(int argc, const VALUE *argv, VALUE _) { rb_io_print(argc, argv, rb_ractor_stdout()); return Qnil; } |