The program does not work properly

I tried running this simple code:

puts 4
i = gets
puts i

It "works", but the console asks for a string, and then prints 4andi

0
source share
5 answers

Add a call flushto gets:

$stdout.flush
+4
source

Instead of an explicit call $stdout.flush:

$stdout.sync = true
+1
source

, ruby ​​1.8.7, 1.9.2 ree. ?

0

? . bash:)

0

, . , "" , , . , .

, , ?

, , : , STDIN STDERR. .

if you want to make sure that the text is displayed before something happens (as in this example), use the "flush" command, as Yossi suggests.

0
source

All Articles