ruby -rpry some_script.rb
- the r means require. If there's a binding.pry
there, you'll be on it.
Pry gives you a graphical look at your program in progress, lets you cd
among objects, ls
to see available variables, etc. You can't step, though; just explore a snapshot at that moment.
Must install debugger gem for your version of Ruby (1.9 is 'gem install debugger'). Doesn't play well with Spork.
rspec some_test_spec.rb --debug
will stop on a debugger
statement.
In a debugging session, set autolist on
says "keep showing me graphically where I am."
l
shows lines of code forward. Has flags:-
backward=
current lineX-Y
lines X to Y
n
is for "next"; "step over"s
is for "step"; "step into"e some_statement
evaluates that. If you want to do more,irb
drops you into it.- hitting enter re-executes the last command; if you hit
n
and want to keep stepping, hit enter. l18
displays line 18- Breakpoints
b file:line [if expr]
sets a breakpointb class(.|#)method [if expr]
sets a breakpointdel [nnn]
deletes some or all breakpoints
- Displaying expressions
disp [expression]
shows value of expression at every stepundisp [nnn]
cancels display options
- Examining the call stack
- May have to call
Debugger.start
first?where
,up
,down
,frame
bashd.sourceforge.net/ruby-debug.html#FrameCommands
- May have to call
help
is available
Put a .rdebugrc
in the project directory or your home directory with:
set autolist
set autoeval
set autoreload
Cool summary, however you can step with pry if you install the pry-debugger plugin, you can also engage in even more sophisticated types of debugging if you install the pry-rescue plugin. For a fuller look at pry plugins available, check out https://github.com/pry/pry/wiki/Available-plugins and the Pry Ecosystem posts.