From: Benoit Daloze Date: 2010-04-30T04:54:24+09:00 Subject: Re: Use of STDOUT.flush after puts --001636417499238e760485657e91 Content-Type: text/plain; charset=ISO-8859-1 On 29 April 2010 21:06, Robert Dober wrote: > On Thu, Apr 29, 2010 at 8:25 PM, hemant wrote: > > Fair enough, may be in that pattern. But for general usage, #reopen > > suffices. But in any case, it may be bikeshedding to further press the > > point. :D > No I do not think so, by using $stdout you are just conceding to the > fact that it is not a constant. > STDOUT is somehow a misconception. > R. > -- > The best way to predict the future is to invent it. > -- Alan Kay > > Hi, If I can add my thoughts: STDIN, STDOUT, STDERR are constants which represent default values for $stdin, $stdout, $stderr. Programming Ruby 1.9 say: "$stdout IO The current standard output. Assignment to $stdout is not permitted: use $stdout. reopen instead." (in 1.9.2 I don't have any problem on doing "$stdout =", while I usually use $> instead) ("$> IO The destination of output for Kernel#print and Kernel#printf. The default value is $stdout.") "STDOUT IO The actual standard output stream for the program. The initial value of $stdout." In fact, the only clean way to keep the standards in/out/err is to keep unmodified these constants (which is normal: they are constants). (By clean I mean not making others constants/global variables) IO#reopen is kind of a trick that shouldn't be allowed on constants(or frozen vars), it's like a #replace. (even worse, it can actually change the class) To the main thread: Clearly, $std{out,in,err}.sync is the best way to go if you want to flush everything. :) Regards, B.D. --001636417499238e760485657e91--