概要
relineのコードリーディングをする。
準備
- relineをクローンする
git@github.com:ruby/reline.git - サンプルコードを作成する
$LOAD_PATH.unshift(File.expand_path('lib', __dir__))
require "reline"
prompt = 'prompt> '
use_history = true
begin
while true
text = Reline.readmultiline(prompt, use_history) do |multiline_input|
# Accept the input until `end` is entered
multiline_input.split.last == "end"
end
puts 'You entered:'
puts text
end
# If you want to exit, type Ctrl-C
rescue Interrupt
puts '^C'
exit 0
end
- 任意の箇所で
binding.irbを挿入する
コードリーディング
サンプルコードをベースにコードリーディングする。
- readlineの呼び出し
- readlineの処理
- 長いので割愛
- 出力
- ruby/reline/blob/master/lib/reline/line_editor.rb#L1323
- 最終的にバッファに溜め込んだ入力をここで出力する