Lane
Lane

Reputation: 695

How to show input history in Ruby?

In Python, we can use import readline to make raw_input() accept UP key to show input history.

Is there any way to do the same thing in Ruby?

Upvotes: 3

Views: 106

Answers (1)

John Douthat
John Douthat

Reputation: 41209

You can use Ruby's readline library, like so.

require "readline"
while buf = Readline.readline("> ", true)
  p buf
end

Readline Documentation

Upvotes: 5

Related Questions