LoginSignup
12
8

More than 1 year has passed since last update.

Rails | pry の入力履歴を半永久的に記憶させる ( pry が終了しても履歴を残す ) [Mac OS X]

Last updated at Posted at 2016-01-27

解決

pry-rails と一緒に rb-readline を入れる。

Gemfile
gem 'pry-rails'
gem 'rb-readline'

$ bundle install

Rails のコンソールを起動する。

$ bundle exec rails console

これで解決だ!
キーボードの上下キーで、以前の入力履歴をたどることが出来る。

image

問題

pry がまったく入力履歴を記録してくれない。

正確に言うと、1セッションの間は記憶してくれるが。
exit すると、次回起動時には全て消えてしまう。

履歴の設定はすべてデフォルトが true だし。
.pry_history が存在することも確認した。

Pry.config.history.should_save # => true
Pry.config.history.should_load # => true
Pry.config.history.file # => "/Users/yinaura/.pry_history"

しかも .pry_history に履歴が書き込まれるのにもかかわらず。
読み込みだけが出来ないのである。

.pryrc にロードの処理を書いても無駄だった。

.pryrc
Pry.history.load

ただし。pry起動後に Pry.history.load を手動実行すると、履歴を読み込むことが出来る。
しかし毎回実行するのは面倒すぎる。

解決策は冒頭のとおり。

環境

  • pry (0.10.3)
  • pry-rails (0.3.4)
  • rb-readline (0.5.3)
  • Rails 4.0.0
  • OSX Yosemit 10.10.4

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

12
8
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
12
8