Prev: cannot freeze my gems
Next: LOGIN INTO YAHOO
From: Alex DeCaria on 28 Apr 2010 11:44 I've seen several examples on this forum where folks have used STDOUT.flush after printing a query to a terminal. For example: puts "Delete indicated item [yes, no]" STDOUT.flush response = gets.chomp What is the purpose of the 'STDOUT.flush', and is it always necessary to use it? What are the possible problems if it isn't used? --Alex -- Posted via http://www.ruby-forum.com/.
From: Dave Baldwin on 28 Apr 2010 11:51 On 28 Apr 2010, at 16:44, Alex DeCaria wrote: > I've seen several examples on this forum where folks have used > STDOUT.flush after printing a query to a terminal. For example: > > puts "Delete indicated item [yes, no]" > STDOUT.flush > response = gets.chomp > > What is the purpose of the 'STDOUT.flush', and is it always necessary to > use it? What are the possible problems if it isn't used? It forces the output to appear immediately, otherwise it may be held in a buffer for some indeterminate time, usually until enough output has accumulated to make it worth while to commit to the terminal, however as you are waiting for input this threshold will never be reached. Dave.
From: Alex DeCaria on 28 Apr 2010 12:58 Thanks! --Alex -- Posted via http://www.ruby-forum.com/.
From: Siep Korteling on 29 Apr 2010 03:16 Dave Baldwin wrote: > On 28 Apr 2010, at 16:44, Alex DeCaria wrote: > >> I've seen several examples on this forum where folks have used >> STDOUT.flush after printing a query to a terminal. For example: >> >> puts "Delete indicated item [yes, no]" >> STDOUT.flush >> response = gets.chomp >> >> What is the purpose of the 'STDOUT.flush', and is it always necessary to >> use it? What are the possible problems if it isn't used? > > It forces the output to appear immediately, otherwise it may be held in > a buffer for some indeterminate time, usually until enough output has > accumulated to make it worth while to commit to the terminal, however as > you are waiting for input this threshold will never be reached. > > Dave. Instead of STDOUT.flush-ing multiple times, you can set STDOUT.sync = true once. -- Posted via http://www.ruby-forum.com/.
From: Robert Dober on 29 Apr 2010 03:58
On Thu, Apr 29, 2010 at 9:16 AM, Siep Korteling <s.korteling(a)gmail.com> wrote: <snip> > Instead of STDOUT.flush-ing multiple times, you can set STDOUT.sync = > true once. And, please, instead of using STDOUT, please use $stdout, this allows your users to mock stdout to somewhere else *without* getting constant redefinition warnings. Cheers R. -- The best way to predict the future is to invent it. -- Alan Kay |