As seen in Python, what is the sys.stdout.write()
equivalent in Ruby?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
.
回答2:
puts "Hello, world!"
or print
- because it buffered.
回答3:
puts
(or print
if you don't want a newline (\n
) automatically appended).