LoginSignup
21
20

More than 5 years have passed since last update.

Ruby の 定番対話ツール pry 徹底攻略 | .pryrc file #pry #ruby

Last updated at Posted at 2015-01-13

Ruby の 定番対話ツール pry 徹底攻略 | .pryrc file

:musical_score: 概要

Ruby の 定番対話ツール pry 徹底攻略
.pryrc file について

The .pryrc file

.pryrc ファイルは .irbrc ファイルと良く似ています。
設定のカスタマイズのために .pryrc ファイルを利用します。

pry を起動すると

  • ~/.pryrc ファイルをチェックして読み込む
  • カレントディレクトリの .pryrc ファイルをチェックして読み込む
  • 両ファイルともにある場合は、 ホームディレクトリの ~/.pryrc ファイルから順に読み込みます。

:large_blue_circle: Loading and :x: suppression

.pryrc ファイルはセッション開始後に最初に読み込まれるファイルです。
.pryrc ファイルは、 plugin や history より早く読み込まれるため、
この二つを制御することが可能です。

.pryrc ファイルの抑止をするには二つの方法があります。

  • pry 起動時に -f option を付与する
$ echo 'puts :hoge' > ~/.pryrc
$ pry
hoge
[1] pry(main)> exit
$ pry -f
[1] pry(main)>
  • セッション開始前に Pry.config.should_load_rc = false を設定する

※無効化により、 ~/.pryrc に仕込んでおいた puts :hoge が動作していないことが分かる

$ echo 'puts :hoge' > ~/.pryrc
$ pry
hoge
[1] pry(main)> exit
$ cat << EOF >> hoge.rb
> require 'pry'
> Pry.config.should_load_rc = false
> binding.pry
> hoge = "hoge"
> EOF

$ ruby hoge.rb

From: /path/to/current/hoge.rb @ line 4 :

    1: require 'pry'
    2: Pry.config.should_load_rc = false
    3: binding.pry
 => 4: hoge = "hoge"

[1] pry(main)> hoge

:sound::seat::wrench::red_car: Customize Pry in your .pryrc

.pryrc ファイルで様々な設定を行うことができます。

  • プロンプトの変更
  • Command のエイリアスの設定
  • Plugin の無効化
  • 履歴のローディング設定

など。

:baby_chick: デフォルト値

こちらのソースコードで確認できます。

pry GitHub default.rb

サンプル

  • :baby_chick: 設定前
$ pry
[1] pry(main)> Pry.plugins.first.last.name
=> "byebug"
[2] pry(main)> Pry.plugins.first.last.enabled
=> true
[3] pry(main)> exit
  • 設定

pry の プロンプトを irb にする
byebug Plugin を無効化する

.pryrc
Pry.config.prompt = [proc { "irb> " },
                     proc { "____| " }]

Pry.plugins["byebug"].disable!
  • :chicken: 設定後
$ pry
hoge
irb> Pry.plugins.first.last.name
=> "byebug"
irb> Pry.plugins.first.last.enabled
=> false
irb> exit

:man::woman: 親記事

Ruby の 定番対話ツール pry 徹底攻略

:books: 外部資料

21
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
20