In Ruby, what is the difference between reassigning an IO stream and using the IO#reopen method? In other words, what is the difference between
$stdout = newfile
and:
$stdout.reopen(newfile)
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.
So basically reopen will associates
$stdoutwith thenewfilestream =>$stdoutandnewfilewill be two File instances associated to the same stream.=will actually assign thenewfileFile instance to$stdout=>$stdoutandnewfilewill be two variables pointing to the same File instance.Consequences:
When using
reopenany change on the instance (that does not affect the stream itself) won’t be reflected in the other instance.=Example:reopenexample: