Posts tagged readline

How to put a prompt before gets.chomp in Ruby

Do you want to ask the user for input at the command line, using a slick 1980’s hacker movie prompt like this: >>?

Don’t use gets.chomp. Use readline instead:

require 'readline'
Readline.readline(">>")

…will output:

>> I can write stuff here