Hi Paul

Paul Brannan wrote:
> 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...
> 

Agreed; they are both references right?

> 
>>  $stdout=f

Which I'd expected to change the reference $stdout to point at the file 
instead...

> 
> 
> ... 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...
> 

Hooked variable? So $stdout isn't a reference after all?

> 
>>  puts("To the file")
>>  $stdout = sso
> 
> 
> ... so that when you get here, this statement is no different from:
> 
>   $stdout = $stdout
> 

Agreed, if $stdout wasn't actually a reference


> 
> The solution is to change the line:
> 
>   sso = $stdout
> 
> to:
> 
>   sso = $stdout.dup
> 


Yep - already discovered that; just wanted to know why when "all 
variables in Ruby are actually references"

Thanks for info

Andrew