Normally I hate to debug apps — we are big fans of test first, but oh
well, sometimes it can be very helpful. The danger starts when one wastes
too much time debugging.
Even when using a IDE it can be very handy to get into a irb session at any
moment.
You need to install ruby-breakpoints
require 'breakpoint'
..
if m==0
puts "m is 0"
pp xs
puts ys.to_yaml
breakpoint
end
..
Useful:
- use CTRL-D (Unix) or CTRL-Z (Windows) or exit to leave the breakpoint and
continue running the program
- use exit! to terminate the program from within a breakpoint
- other interesting things to check out include: local_variables,
instance_variables, caller, methods
- just type the name of your variable to check its value
- Note that you can enter any type of regular Ruby code into a breakpoint IRB
shell. You can even hot patch your deployed code to fix a problem at
run-time!
If you are developing a rails app, check out the wiki entry.
I take my break now. Off for yammie food.