Wednesday, May 9, 2012

Ruby: Get input from console

Share at Facebook

You can use the STDIN to get the input from console(shell/cmd/commandline).

to get a single character from the user.
chr = STDIN.getc

This is useful to implement something like "Press Enter to exit program." kind of things.

you can use gets, readline, etc with the STDIN.

FYI: for writing output to the screen, you need to use STDOUT.

No comments: