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
2010-06-23 11:31:38
thanks sir its working....
amit singh tomar
2010-06-23 11:37:36
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
2010-06-23 11:40:07
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
2010-06-23 11:44:57
cud u expain it more sir
amit singh tomar
2010-06-23 11:50:07
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
2010-06-23 15:27:14
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
2010-06-24 06:01:17
if the program ends the buffer gets flushed automaticaly
Nikolaus Gradwohl
2010-06-24 07:01:16