1. Computing

Breakpoints

By

Breakpoints are lines on which you want the program to stop execution. When the program reaches such a line, the debugger will stop execution and allow you to take control of the program. Breakpoints can be set on line numbers or on more descriptive things (such as methods).

Breakpoints can be set with the b command. It takes a single argument; the line of code or method name you want to break on. If you don't specify any line or method name, the breakpoint command will list all active breakpoints.

$ ruby -rdebug problem.rb data.txt
Debug.rb
Emacs support available.

problem.rb:3:lines = File.readlines(ARGV[0])
(rdb:1) l
[-2, 7] in problem.rb
1
2
=> 3 lines = File.readlines(ARGV[0])
4
5 lines.each do|l|
6 nums = l.split /,/
7 nums.map!{|n| n.to_f }
(rdb:1) b 7
Set breakpoint 1 at problem.rb:7
(rdb:1) b
Breakpoints:
1 problem.rb:7

(rdb:1) exit
  1. About.com
  2. Computing
  3. Ruby
  4. Advanced Ruby
  5. Breakpoints

©2014 About.com. All rights reserved.