Consider this code:

puts(gets)
$stdin = File.open("alternate-in", "r")
puts(gets)

Suppose ruby is run like this:
% ruby stdin.rb < in

where file "in" contains lines like "in", and the file "alternate-in" 
contains lines like "alternate-in". I expect the output to be:

in
alternate-in

In fact, for 1.6.3 on NT, the result is:

in
in

I suppose input is buffered and the buffer is carried over to the new stream.

I know that $stdin.reopen("alternate-in") will work, but I cannot find a 
way to put $stdin back to its original value. So I don't see how you can 
temporarily redirect $stdin. Perhaps the answer is just "you shouldn't ever 
want to", which actually would be OK with me.

--
Brian Marick, marick / testing.com
www.testing.com - Software testing services and resources
www.testingcraft.com - Where software testers exchange techniques
www.visibleworkings.com - Adequate understanding of system internals