As seen in Python, what is the sys.stdout.write()
equivalent in Ruby?
A built-in file object that is analogous to the interpreter's standard output stream in Python. stdout is used to display output directly to the screen console. Output can be of any form, it can be output from a print statement, an expression statement, and even a prompt direct for input.
In Ruby, $stdout represents the current standard output and a global variable. It means we can also use it to output data.
Ruby has another three methods for printing output. In the example, we present the p , printf and putc methods. The p calls the inspect method upon the object being printed. The method is useful for debugging.
In Ruby, you can access standard out with $stdout
or STDOUT
. So you can use the write method like this:
$stdout.write 'Hello, World!'
or equivalently:
STDOUT.write 'Hello, World!'
$stdout
is a actually a global variable whose default value is STDOUT
.
You could also use puts
, but I think that is more analogous to python's print
.
puts
(or print
if you don't want a newline (\n
) automatically appended).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With