Mon 7 May 2007
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
- def fib(n)
- @fib_cache ||= [1, 1]
- @fib_cache[n] ||= fib(n-1) + fib(n-2)
- end
- puts fib(20)
Next screencast will cover debugging a Rails application.
May 10th, 2007 at 03.25
Sweet screencast.
May 10th, 2007 at 05.43
Like it. Thanks.
May 14th, 2007 at 01.44
Thanks! Looking forward to the next one.
May 14th, 2007 at 21.36
Great job! Looking forward to the next ‘cast.
May 28th, 2007 at 17.49
[…] Watch […]
July 13th, 2007 at 21.53
Thanks for this.
Looks like the second one for a rails app isn’t up yet.
..guess I’ll have to RTFM..
July 19th, 2007 at 17.31
Thanks for this. Gyre seems an interesting way to debug as well, more GUI and built in rails and open source.
July 30th, 2007 at 15.56
this topic was in need of a screencast. thanks!
September 20th, 2007 at 15.03
Nice work - would love to see a second one.
October 7th, 2007 at 10.40
Great screencast. Very helpful with learning rdebug. Can’t wait to see the one for Rails apps.
October 18th, 2007 at 04.39
Great stuff, one point though, fib(1)==fib(2)==1 and
@fibcache[0]==@fibcache[1]==1 so I think the third line should be
@fib_cache[n-1] ||= fib(n-1) + fib(n-2)
as @fib_cache[n-1] stores fib(n)…
(FIXME)
November 4th, 2007 at 12.31
Sweet.
November 4th, 2007 at 12.36
BTW: For folks wanting to learn how to debug a Rails application, download Patrick Lenz’s book
From the sitepoint site. In chapter 11, Patrick shows a rails app debug with ruby debug.
The bottom line is quite simple: After the gem ruby-debug is installed, you simply insert a debugger statement where you would previously put a breakpoint statement. The Server stops at that execution point and hands control to the ruby debugger. From then on this screencast describes everything you need.
November 4th, 2007 at 13.56
Oops, forgot one step: You need to add a require “ruby-debug” line on your environment.rb.
December 16th, 2007 at 04.21
That was excellent.
Thanks.
April 29th, 2008 at 14.50
thanks! Short, sweet and to the point.
July 11th, 2008 at 06.51
Thanks! Nice work. Would love to see the Rails one!