0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby on Rails デバッガまとめ

Posted at

RoRでデバッグ

はじめに

システム情報

  • Ruby 2.6.5
  • Rails 5.2.3
  • bundler 1.17.2
  • puma
  • rbenv local環境下

デバッグ用のライブラリ群

pry-railsrubygems

Rails console で Pry が起動するようになる
pry-rails を入れるまでは irb が起動する
show-routes などのコマンドが Rails console で使えるようになる
Rails console で help と打つと、使えるコマンドがわかる
binding.pry をソースコード中に挟むとそこがブレークポイントとなり、そこで処理を止めてデバッグできるようになる
pry-rails だけではステップ実行はできない

pryの使い方

Rails-console
> help

**Navigating pry**
  !pry               Start a pry session on current self.
  disable-pry        Stops all future calls to pry and exits the current session.
  exit               Pop the previous binding.
  exit-all           End the current pry session. ブレークポイントで停止した状態から解放するデバッグの終了
  exit-program       End the current program.
  jump-to            Jump to a binding further up the stack.
  nesting            Show nesting information.
  switch-to          Start a new subsession on a binding in the current stack.

チュートリアルをここに差し込み予定

pry-byebugrubygems

binding.pry で止めたところからステップ実行ができる
例えば next コマンドで一行ずつ実行できる
こちらも詳細は Rails console の help などを参照

byebugの使い方

Rails-console
> help
**Byebug**
  backtrace          Display the current stack.
  break              Set or edit a breakpoint.
  continue           Continue program execution and end the pry session.ブレークポイントで停止した状態から解放するデバッグの終了
  down               Move current frame down.
  finish             Execute until current stack frame returns. 現在のスタックを終了するステップアウトレシーバ呼び出し部分に戻る
  frame              Move to specified frame #.
  next               Execute the next line within the current stack frame. ステップの次に移動するが内部処理には入らないステップオーバー
  step               Step execution into the next line or method. ステップの次に移動するが内部処理に入るステップイン
  up                 Move current frame up. レシーバ呼び出し部分に戻る

Pry-byebug (v3.7.0)
  exit-all           End the current pry session.

チュートリアルをここに差し込み予定

エイリアスを作成してコマンド短縮

.pryrc
if defined?(PryByebug)
  Pry.commands.alias_command 's', 'step'
  Pry.commands.alias_command 'n', 'next'
  Pry.commands.alias_command 'f', 'finish'
  Pry.commands.alias_command 'c', 'continue'
end

pry-docrubygems

show-method コマンドで C で書かれたコードやドキュメントも出力できるようになる
show-method は Pry のコマンドで通常は Ruby で書かれたコードやドキュメントのみ出力できる

pry-docの使い方

チュートリアルをここに差し込み予定

注釈

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?