るりまサーチ

最速Rubyリファレンスマニュアル検索!
22件ヒット [1-22件を表示] (0.051秒)
トップページ > クエリ:-[x] > クエリ:to_a[x] > ライブラリ:readline[x]

別のキーワード

  1. _builtin to_s
  2. openssl to_der
  3. openssl to_s
  4. _builtin to_a
  5. openssl to_pem

モジュール

オブジェクト

キーワード

検索結果

Readline::HISTORY.delete_at(index) -> String | nil (140.0)

index で指定したインデックスの内容をヒストリから削除し、その内容を返します。 該当する index の内容がヒストリになければ、 nil を返します。 index に 0 を指定すると Readline::HISTORY.shift と同様に最初の入力内容を削除します。 また、 -1 は最後の入力内容というように、index に負の値を指定することで、 最後から入力内容を取得することもできます。 index が -1 の場合は Readline::HISTORY.pop と同様に動作します。

...すると Readline::HISTORY.shift
と同様に最初の入力内容を削除します。
また、 -1 は最後の入力内容というように、index に負の値を指定することで、
最後から入力内容を取得することもできます。
index が -1 の場合は Readline::HISTORY...
...のヒストリのインデックスを指定します。

@raise NotImplementedError サポートしていない環境で発生します。

例:

require "readline"

Readline
::HISTORY.push("foo", "bar", "baz")
Readline
::HISTORY.delete_at(1)
p Readline::HISTORY.to_a #=> ["foo", "baz"]...

Readline.#readline(prompt = "", add_hist = false) -> String | nil (132.0)

prompt を出力し、ユーザからのキー入力を待ちます。 エンターキーの押下などでユーザが文字列を入力し終えると、 入力した文字列を返します。 このとき、add_hist が true であれば、入力した文字列を入力履歴に追加します。 何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、 ユーザからの入力がない場合は nil を返します。

...:

require "readline"

input = Readline.readline
(プロンプトなどは表示せずに、入力待ちの状態になります。
ここでは「abc」を入力後、エンターキーを押したと想定します。)
abc

p input # => "abc"

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

stty_save = `stty -g`.chomp
begin
while buf = Readline.readline
p buf
end
rescue Interrupt
system("stty", stty_save)
exit
end

例: INTシグナルを捕捉して、端末状態を復帰する。

require 'readline'

stty_save = `stty -g`.chomp...
...line.readline
p buf
end

入力履歴 Readline::HISTORY を使用して、次のようなこともできます。

例: 空行や直前の入力と同じ内容は入力履歴に残さない。

require 'readline'

while buf = Readline.readline("> ", true)
# p Readline::HISTORY.to_a...