Rick Denatale wrote:
> On Sat, Jun 6, 2009 at 7:57 AM, Kga Agk<lord_kga / yahoo.no> wrote:
>> test2.rb
>>
>> testing
>>
> 
> This works:
> 
> def testing
>   t = gets
>   puts t
> 
>   k = gets
>   puts k
> 
> end
> 
> 
> require 'stringio'
> 
> $stdin = StringIO.new("abc\ndef\n")
> 
> testing
> 
> Of course you'd want to set $stdin to the open file.

A bit of care is needed, because if the program is given command-line 
arguments, Kernel#gets will read from the files listed on the 
command-line (in the same way as ARGF.gets, I believe)

If test.rb really wants to read from stdin, it should do

    $stdin.gets

Of course, you already said you couldn't modify test.rb. So perhaps you 
need to do ARGV.clear or something like that.
-- 
Posted via http://www.ruby-forum.com/.