Debugging Ruby Apps Step by Step

There is always the time in a programmers life, you are stuck with a app where you really don’t know what went wrong. Fortunately there is a way to execute your app step by step and see what’s going on. To do this install the debugger gem. In your terminal type the following


$ gem install debugger

And it gets installed.

Usage

Take a look at the program


require 'debugger'

def sum a, b
  debugger # place this line where breakpoint is needed
  c = a + b
end

puts "Sum of 3 and 5 is #{sum 3,5}"

Notice that I have placed a debugger point in line 4 , the program will stop at that point. You can type disp a to display the value of variable a in function sum. To goto the next step press n or next. To continue after the debug point type c or continue . If at all you want to get help, run the program and type help to see quiet good bit of help built into it. Enjoy debugging!

Advertisements

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: