tags:

views:

86

answers:

3

as seen in python, what is the "sys.stdout.write()" equivalent in ruby?

+1  A: 

puts (or print if you don't want a newline (\n) automatically appended).

Jordan
+1  A: 
puts "Hello, world!"

or print - because it buffered.

philippe
+8  A: 

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.

Whisty