Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show input history in Ruby?

Tags:

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?

like image 343
Lane Avatar asked Dec 21 '25 02:12

Lane


1 Answers

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

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

Readline Documentation

like image 103
John Douthat Avatar answered Dec 23 '25 21:12

John Douthat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!