16.3. Using the Ruby Debugger

Truthfully, the Ruby debugger does not seem to get much use. I do not use it, and I have talked to very few who do. But it’s nice to know that it’s there. Here’s a brief description of how it works.

Invoke the debugger simply by requiring the debug library. This can be done on the command line:

ruby -rdebug myfile.rb

At the prompt (which looks like (rdb:1) ), you can type such commands as list to list any or all of the program, step to step into a method call, and so on. A few of these commands are listed in Table 16.1 (with the abbreviation in boldface).

Table 16.1. Common Debugger Commands
CommandDescription
breakList or set a breakpoint.
deleteDelete some or all breakpoints.
catchList or set a catchpoint.
stepStep ...

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.