Figuring out what’s wrong in Ruby can be a pain. That dynamic typing that you find so nice while writing code can sometimes work against you when reading it — and troubleshooting it. What most of us end up resorting to is basically one step up from how most JS debugging happens: puts.

While this is annoying, it doesn’t have to be this way. Ruby comes with a debugger, but it is slow on non-trivial applications. The best alternative is a gem called Ruby Debug, which is fast and has a bunch of goodies. I come from the GUI-debugging world of VS.NET and IDEA, so getting into Ruby Debug was a little bit of a challenge for me at first. If you come from the gdb world you should feel right at home.

Watch the Ruby Debug Basics screencast

from the screencast: fib.rb

  1. def fib(n)
  2. @fib_cache ||= [1, 1]
  3. @fib_cache[n] ||= fib(n-1) + fib(n-2)
  4. end
  5.  
  6. puts fib(20)

Next screencast will cover debugging a Rails application.