relineのコードリーディング

アプリケーション

概要

relineのコードリーディングをする。

準備

  1. relineをクローンする git@github.com:ruby/reline.git
  2. サンプルコードを作成する
$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
  1. 任意の箇所でbinding.irbを挿入する

コードリーディング

サンプルコードをベースにコードリーディングする。

  1. readlineの呼び出し
  1. readlineの処理
  • 長いので割愛
  1. 出力

関連書籍