From: Siep Korteling Date: 2010-04-29T16:16:45+09:00 Subject: Re: Use of STDOUT.flush after puts 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/.