Using the Ruby Debugger

A debugger is a special tool used to provide insight into an application while it’s executing. Instead of merely running some code and outputting the result, a debugger can be used to pause the execution, move around within the execution logic, print the values of variables at any point, and so much more. Ruby comes with a debugger built into the Standard Library. To use that debugger, you can formally include it in a script:

require 'debug'

A more logical solution is to require the library on the fly, when you go to execute the script. You can do so by using the -r flag when invoking the Ruby executable, following it with the name of the library to include:

ruby -r debug scriptname.rb

That line tells Ruby to include ...

Get Ruby: Visual Quickstart Guide 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.