From: hemant Date: 2010-04-30T05:28:16+09:00 Subject: Re: Use of STDOUT.flush after puts Hi On Fri, Apr 30, 2010 at 1:24 AM, Benoit Daloze wrote: > > 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." Perhaps "not permitted" is too strong a word. Not advisable is better. > (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) Ruby standard library uses IO#reopen many places on STDOUT. I am not saying since Ruby standard library does that, it has to be best practice, but in above context it really depends on implementation. For example, in many languages you can have a constant variable and while you can't assign anything else to variable you can add/remove stuff to object to which the variable points. How is reopen different that that? How can reopen change the class btw? Ruby is not a class oriented language btw. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org