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
Should I use gets.chomp or Readline for user input in Ruby?
Use Readline.readline()
. That’s what irb
uses for user input.
Don’t use gets.chomp
.
How to get rid of control characters like ^[[D in Ruby's gets.chomp
You’re coding some Ruby. You use gets.chomp
to get user input. You run your ruby file. You type some text at the prompt. Looks good, right? But then you press the left arrow key and… ^[[D
appears on the screen. WTF is that?