LoginSignup
0
0

More than 5 years have passed since last update.

RubyでCLIから入力を求めるとき

Posted at

Kernel#gets を使うと、バックスペースなどの制御コードが文字として入力されてしまい残念な事になる。

irb(main):001:0> s = gets
abce^?d^[[D^[[D
=> "abce\u007Fd\e[D\e[D\n"

Readline.readline を使うと、行の編集が出来るため便利。

irb(main):002:0> s = Readline.readline('> ', false)
> abcdef
=> "abcdef"

という事で良いのだろうか?readline ではない、他の組み込みライブラリや標準添付ライブラリで上手くやれたりするだろうか。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0