IRBを読む
https://github.com/ruby/irb
https://rubygems-code-reading.connpass.com/event/337903/
https://github.com/ruby/repl_type_completor
Ruby 3.4からデフォルトで使おうとする
https://github.com/ruby/irb/blob/9750fa23cc0aa4e0ef2cd570e22c49c0ca4f1862/lib/irb.rb#L895
$0
https://docs.ruby-lang.org/ja/3.4/method/Kernel/v/0.html
これを設定しておくことでpsの出力がirbになる
IRB.setup
https://github.com/ruby/irb/blob/bb6a99d81574204fa79b54a9ef33f56b9dbeff47/lib/irb/init.rb#L50
IRB.init_config
https://github.com/ruby/irb/blob/bb6a99d81574204fa79b54a9ef33f56b9dbeff47/lib/irb/init.rb#L65
IRB.conf:PROMPT_MODE = :MY_PROMPT
IRB.conf:PROMPT:MY_PROMPT = {
:PROMPT_I => "%N(\e[34m%m\e[0m):%03n> ",
:PROMPT_S => "%N(\e[34m%m\e[0m):%03n%l ",
:PROMPT_C => "%N(\e[34m%m\e[0m):%03n* ",
:RETURN => "%s\n"
}
こういう感じで追加もできる
https://github.com/ruby/irb/commit/9957e83f7d727524e9a2fd56827c03a8545586f6#diff-f9b03212edb2ad71662a5aa868477764516ea8e90bc2ed556f26e73f2511cf07R263
そろそろ消せるかも
IRB.run_config
https://github.com/ruby/irb/blob/bb6a99d81574204fa79b54a9ef33f56b9dbeff47/lib/irb/init.rb#L397
IRB.prepare_irbrc_name_generators
https://github.com/ruby/irb/blob/bb6a99d81574204fa79b54a9ef33f56b9dbeff47/lib/irb/init.rb#L479
IRB.rc_file_generators
https://github.com/ruby/irb/blob/bb6a99d81574204fa79b54a9ef33f56b9dbeff47/lib/irb/init.rb#L498
rc系のファイルを読み込み
末尾を考慮
IRB.validate_config
https://github.com/ruby/irb/blob/bb6a99d81574204fa79b54a9ef33f56b9dbeff47/lib/irb/init.rb#L431-L430
IRB.load_modules
https://github.com/ruby/irb/blob/bb6a99d81574204fa79b54a9ef33f56b9dbeff47/lib/irb/init.rb#L466
松田さん談
IRB は大元は keiju さんが作っていたプロダクト
for を使ったり独特の keiju スタイルのコーディングスタイル
その後糸柳さんが引き継いだ
糸柳さんは original のコーディングスタイルを崩さないというポリシー
IRB::Context
https://github.com/ruby/irb/blob/f1e25ec7aeeda8e2f5d1de98b461fb95766f8cf2/lib/irb/context.rb
IRB::Context#initialize
https://github.com/ruby/irb/blob/f1e25ec7aeeda8e2f5d1de98b461fb95766f8cf2/lib/irb/context.rb#L27
IRB::Context#build_completor
https://github.com/ruby/irb/blob/f1e25ec7aeeda8e2f5d1de98b461fb95766f8cf2/lib/irb/context.rb#L180
IRB::RegexpCompletor#completion_candidates
https://github.com/ruby/irb/blob/f1e25ec7aeeda8e2f5d1de98b461fb95766f8cf2/lib/irb/completion.rb#L208
IRB::WorkSpace#load_helper_methods_to_main
https://github.com/ruby/irb/blob/2f1c5938018ccc7cec07e37359bb4bf28d933d40/lib/irb/workspace.rb#L90
ruby/irb#1031 Don't use delegator to install helper methods to main object
IRB::HelperMethod::Conf
https://github.com/ruby/irb/blob/8cde57f55a5a580f35bd4487515dbc9d88ea2090/lib/irb/helper_method/conf.rb
できるなら消したい
IRB::RubyLex
https://github.com/ruby/irb/blob/cdaa356df2c4e2636ee2eeb906f2b73ab55b8549/lib/irb/ruby-lex.rb
最古の Lexer
Ruby 本体と同期を取る必要がある
最初期のruby-lex
https://github.com/ruby/irb/blob/8c2a0d89a9865ced0b783655e9eedde0e4c07e50/lib/irb/ruby-lex.rb
Prism で置き換えようという Issue も出ている
https://github.com/ruby/irb/issues/1024
- でファイル名を区切るのも keiju スタイル
Module#attr
https://docs.ruby-lang.org/ja/latest/method/Module/i/attr.html
IRB::Irb#run
https://github.com/ruby/irb/blob/9750fa23cc0aa4e0ef2cd570e22c49c0ca4f1862/lib/irb.rb#L1001
RubyVM.keep_script_lines
https://docs.ruby-lang.org/en/master/RubyVM.html#method-c-keep_script_line
るりまにはないのでコントリビュートチャンス
IRB::Irb#eval_input
https://github.com/ruby/irb/blob/9750fa23cc0aa4e0ef2cd570e22c49c0ca4f1862/lib/irb.rb#L1041
IRB::Context#parse_command
https://github.com/ruby/irb/blob/f1e25ec7aeeda8e2f5d1de98b461fb95766f8cf2/lib/irb/context.rb#L636
irb の中で cd = xxx とかやると cd コマンドが使えなくなる
irb_cd というコマンドが用意されている
IRB::WorkSpace#evaluate
https://github.com/ruby/irb/blob/2f1c5938018ccc7cec07e37359bb4bf28d933d40/lib/irb/workspace.rb#L100
Object::TOPLEVEL_BINDING
https://docs.ruby-lang.org/ja/latest/method/Object/c/TOPLEVEL_BINDING.html
IRB::TOPLEVEL_BINDING
多分最初にはいったのがこれ
https://github.com/ruby/irb/commit/b12f0cb8e2fddff3e33a52de57c0e3c63a62e650
https://github.com/ruby/irb/pull/206
https://bugs.ruby-lang.org/issues/17623
send で easter_egg を呼べちゃう
https://techracho.bpsinc.jp/hachi8833/2021_03_09/104577
が、意図しないもの
irb を起動して RubyVM で tab を入力することでも出せる