O'Reilly logo

Sams Teach Yourself Ruby in 21 Days by Mark Slagell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Built-In Debugger

Put -r debug (the space is optional; -rdebug works too) on the Ruby command line with a script name, and you get access to lots of diagnostic tools, making it unnecessary to sprinkle your code with diagnostic messages.

The debugger gives you what amounts to an intelligent pause control, letting you freeze a script's execution and examine the contents of variables at any time. How that pause control is invoked can vary depending on your needs.

Any time you're in the debugger, you can enter an h (for help) command to get a list, like the following, of all the things you can do there.

~/testcode:>ruby
						-r debug div0.rb
Debug.rb
Emacs support available.

div0.rb:3:def foo
(rdb:1) h Debugger help v.-0.002b Commands b[reak] [file|method:]<line|method> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required