tags:

views:

24

answers:

1

again i m asking this question how to produce delay in ruby puts"amit" sleep(10) puts "asda" i want delay between two statement when i tried the above example first i have a delay of 10 sec than both statement execute that ui don't want plzzzz help me

A: 

looks like the puts statement writes the text to the output buffer, but doesn't flush it at the newline

try to add

$stdout.flush

after the print statements

your programm should look like this

puts "foo"
$stdout.flush
sleep(10)
puts "bar"
Nikolaus Gradwohl
thanks sir its working....
amit singh tomar
but sir if i use any statement like print than also works??or how to produce delay between ruby not only between puts statement
amit singh tomar
The puts statement is called 10 second later but the operating system bufferes the output of the first statement until either you flush the buffer or the buffer is full
Nikolaus Gradwohl
cud u expain it more sir
amit singh tomar
if you ask the operating system to print something on the screen or the terminal (by calling puts for example) it first stores the string into a buffer (for performance reasons) and writes the buffer to the screen if the buffer is full, or if your program tells it so by calling flush
Nikolaus Gradwohl
but if i m writing simply puts "amit" then it simply print amit to screen without explicitly calling flush .is it means buffer is full??
amit singh tomar
if the program ends the buffer gets flushed automaticaly
Nikolaus Gradwohl