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!
October 17th, 2008 at 08.51
nice… what did you use to create the screencast?
January 18th, 2009 at 08.45
[…] Re: errors with hawler gem on os x 10.5 Of course, a search of the forum was in order and I found this: http://brian.maybeyoureinsane.net/bl…cs-screencast/ Pauli Price wrote: > [asking about debugging technique] — Posted via http://www.ruby-forum.com/. « Regular Expressions | DNS-SD Gem (0.6.0) on OSX Leopard 10.5.3 » […]
March 29th, 2009 at 14.46
Keep up the excellent work! Your website helps to keep me from boredom as well.
April 3rd, 2009 at 20.42
Hi Brian. The debugger is awesome. I’ve used it widely. But, unfortunately, you can’t run irb under debugger anymore with rails 2.3.2 =( When you reaching breakpoint
> (rdb:5)
and trying to run irb
> (rdb:5) irb
you get an error
> INTERNAL ERROR!!! Unrecognized switch: –debugger
Full trace here:
http://pastie.org/436603.txt
But everything works when you specify RAILSGEMVERSION as 2.2.2 or 2.1.2
irb without debugger works fine, script/console works fine.(with 2.3.2)
My system is: Ubuntu Linux 8.10
Kernel: 2.6.27-7-generic
Ruby: ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
Do you know what’s wrong?
April 4th, 2009 at 02.42
all right.
running with
> $ rdebug ./script/server
fix the problem. Push “c” after starting up
April 8th, 2009 at 01.10
awesome wicked sweet.
i’m a nuby, and have never used a debugger but this vid made it perfectly doable and utterly clear and real.
and.. what did you use to do the screencast?
the rubyworld is too much. can’t wait for the future to be ever more Time.now
April 28th, 2009 at 01.48
[…] Now that you have this set up, take a look at this Railscast by Ryan Bates or this one by Brian Donovan to get an idea of just how useful the ruby debugger is. […]
June 23rd, 2009 at 05.59
thank you! That looks like a great resource
August 26th, 2009 at 04.04
wow, realy good, thanks to share.
sarah lys manager
October 28th, 2009 at 04.36
nice post mate…..
web design
January 20th, 2010 at 07.39
all right.
running with
> $ rdebug ./script/server
fix the problem. Push “c” after starting up
Thanks
February 6th, 2010 at 02.41
We get know about this good post from the various sources. Moreover, everybody will propose to buy essay at the writing services. So, men very often buy custom written essays.
March 1st, 2010 at 23.50
Top website designing company in India, Surat provding world class design and solutions.
Surat SEO, SEO Company Surat, Website Design Services Surat, Surat Website Development Services
March 9th, 2010 at 18.19
I know you have seen these folks who seem to be able to get levels fast in World Of Warcraft and race to level 70 with lightning speed.wow cd keyWoW Goldlast chaos gold These are the same people who spur on all those searches online for cheat codes
March 9th, 2010 at 18.23
Long before the World of Iris was torn apart by war, Eres (God of Darkness) and Apollon (God of Light) joined forces to create a world inhabited by mortals. StarCraft II Beta KeyStarCraft 2 Beta KeyThe balance of power is in your hands, choose wisely and enter into what is the Last Chaos!
March 12th, 2010 at 22.26
Some time ago, I did need to buy a car for my organization but I did not have enough cash and could not buy something. Thank God my friend adviced to try to take the loan at banks. Hence, I did so and was satisfied with my small business loan.