In Ruby, what is the difference between
$stdout (preceded by a dollar sign) and
STDOUT (in all caps)? When doing output redirection, which should be used and why? The same goes for
Edit: Just found a related question.
Same goes for
Hope this helps.
So, to answer the other part of your question, use the global variables to redirect output, not the constants. Just be careful to change it back further on in your code, re-defining global variables can impact other parts of your application.
If you are using the shell to do redirection, for example:
Then it doesn't matter which one you use as the file descriptor for your script is being determined before your script is executed.
However, if you are trying to change the file descriptor for stdout from within your Ruby script, for example to send output to a rotating set of log files based on the current day of the week, then you'll want to make sure you use