On Fri, May 02, 2003 at 11:15:03PM +0900, Andrew Walrond wrote:
> File.open("output","w") { |f|
>   puts("To the screen")
>   sso = $stdout

This makes sso refer to the same object as $stdout does...

>   $stdout=f

... but since $stdout is a hooked variable, this doesn't change the
object that $stdout refers to; it instead calls dup2() on the underlying
file descriptor...

>   puts("To the file")
>   $stdout = sso

... so that when you get here, this statement is no different from:

  $stdout = $stdout

>   puts("To the screen again")
> }

The solution is to change the line:

  sso = $stdout

to:

  sso = $stdout.dup

Paul