7. Otemachi.rb #15 発表資料 「pry による REPL 駆動開発について」
?、show-doc、$、show-method
? や show-doc を使うとドキュメントを確認できる
$ や show-method を使うとメソッドの定義を確認で
きる
6
pry(main)> ? {}.values_at
From: hash.c (C Method):
Owner: Hash
Visibility: public
Signature: values_at(*arg1)
Number of lines: 5
Return an array containing the values associated with the
given keys.
Also see Hash.select.
h = { "cat" => "feline", "dog" => "canine", "cow" =>
"bovine" }
h.values_at("cow", "cat") #=> ["bovine", "feline"]
8. Otemachi.rb #15 発表資料 「pry による REPL 駆動開発について」
cd、ls 、TAB補完
cd でコンテキストを移動できる
ls で、オブジェクトの持つメソッド、インスタンス変数
などを一覧で確認できる
候補となる単語をタブで補完できる
7
pry(main)> ls []
pry(main)> cd []
pry(#<Array>):1> ls
pry(#<Array>):1> cd ..
pry(main)>
12. Otemachi.rb #15 発表資料 「pry による REPL 駆動開発について」
help
pry のコマンドの全リストを確認できる
11
[1] pry(main)> help
Help
help Show a list of commands or information about a specific
command.
Context
cd Move into a new context (object or scope).
find-method Recursively search for a method within a class/module or
the current namespace.
ls Show the list of vars and methods in the current scope.