Ruby comes with a debugger,
which is conveniently built into the base
system. You can run the debugger by invoking the interpreter with the
option, along with any other Ruby options and the name of
ruby -r debug [
The debugger supports the usual range of features you'd expect,
including the ability to set breakpoints, to step into and step over
method calls, and to display stack frames and variables.
It can also list the instance methods defined for a particular object
or class, and allows you to list and control separate threads within
Ruby. Table 12.1 on page 131 lists all of
the commands that are available under the debugger.
If your Ruby has
support enabled, you can use cursor
move back and forth in command history and use line editing commands to
amend previous input.
To give you an idea of what the Ruby debugger is like, here
is a sample session.
ruby -rdebug t.rb
Emacs support available.
[1, 10] in t.rb
=> 1 def fact(n)
2 if n <= 0
5 n * fact(n-1)
9 p fact(5)
Set breakpoint 1 at t.rb:2
breakpoint 1, fact at t.rb:2
t.rb:2: if n <= 0
1: n = 5
Set watchpoint 2
watchpoint 2, fact at t.rb:fact
1: n = 1
--> #1 t.rb:1:in `fact'
#2 t.rb:5:in `fact'
#3 t.rb:5:in `fact'
#4 t.rb:5:in `fact'
#5 t.rb:5:in `fact'