Is this possible?

J

James Smith

Is there anyway to override the STDIN of a ruby program, do that when a
command such as 'gets' is called somewhere randomly in the program, I am
able to control what action is taken. i.e. i don't want it to block if
there is nothing in the STDIN buffer, i would like to be able to do my
own thing.

NOTE: the programs will be generated randomly, so i can't just call a
different method (one i defined). But i can add to the code..

Thanks for your time
 
A

Aredridel

Is there anyway to override the STDIN of a ruby program, do that when a
command such as 'gets' is called somewhere randomly in the program, I am
able to control what action is taken. i.e. i don't want it to block if
there is nothing in the STDIN buffer, i would like to be able to do my
own thing.

NOTE: the programs will be generated randomly, so i can't just call a
different method (one i defined). But i can add to the code..

You can use IO#reopen on STDIN, or you can undefine the constant and
then redefine it.

Aria
 
J

James Smith

Aredridel said:
You can use IO#reopen on STDIN, or you can undefine the constant and
then redefine it.

Aria

Do you think you could expand? (i am fairly new to Ruby) what actually
happens when, for example, 'gets' is called? Does it just try and read
from the STDIN variable and then block if this is equal to 'nil' ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,219
Messages
2,571,117
Members
47,729
Latest member
taulaju99

Latest Threads

Top