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 $stderr and STDERR.
Edit: Just found a related question.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$stdoutis a global variable that represents the current standard output.STDOUTis a constant representing standard output and is typically the default value of$stdout.With
STDOUTbeing a constant, you shouldn’t re-define it, however, you can re-define$stdoutwithout errors/warnings (re-definingSTDOUTwill raise a warning). for example, you can do:Same goes for
$stderrandSTDERRSo, 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.