How to incorporate Interactive Ruby into my development process?
Asked Answered
A

5

6

I am trying to find a better way to integrate IRB with my normal ruby devleopment. Currently I rarely use IRB with my code. I only use it to verify syntax or to try something small.

I know I can load my own code into ruby as a

require 'mycode'

but this usually doesn't mesh with my programming style. Sometimes the variables I want to examine are out of scope or inside of a loop. Is there an easy way to fire up my script and freeze at a certain point inside of IRB? I guess I'm looking for an easier way to debug my ruby code without breaking my F5(compile) key.

Maybe a more experienced ruby developer can share with me a more streamlined method of development.

Ascariasis answered 27/9, 2008 at 17:17 Comment(1)
Develop test-first (preferably with RSpec and Cucumber). Then you won't need IRB much at all. But yeah, debugger breakpoints are the way to go, as others have already said.Felske
S
10

Install the ruby-debug gem. Of course, require it inside your app (only in development/test mode). Now you can write 'debugger' where you want to stop execution.

Once your app stop at your breakpoint, you can type 'help' to know about all commands. One of them is 'irb'. It starts an IRB session in which you have access to all methods in your current context.

I personally mostly use p (print), eval, v i (instance vars) and v l (local vars). Of course, n for next and c for continue.

The command to step out of a given block/method never worked for me though. I never investigated why :-)

Skite answered 28/9, 2008 at 0:44 Comment(1)
I have a textmate/e snippet which inserts "require 'ruby-debug'; debugger". I use it about 10 times a day. It's awesome :-)Halsy
C
2

I don't tend to use irb directly that frequently, as I tend to be inside rails and so use script/console a bunch, but I do like using the ruby debugger (Ruby Debug gem). It lets you set a breakpoint basically and then step through your code line by line.

Here's a screencast about it that I haven't actually watched, but a quick search pulled it up, and it could be useful:

http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/

Carbone answered 27/9, 2008 at 17:25 Comment(0)
K
1

For Ruby development in Eclipse: there's a much improved version of RDT (ruby development tools) available now. To install it directly in Eclipse, click Help > Software Updates > Find and Install > Search for new features radio button > next > new remote Site > Name = Ruby and URL = http://update.aptana.com/update/rdt/3.2/

Another Ruby plugin is the shiny new Eclipse DLTK (dynamic languages toolkit). DLTK stable release 1.0.M5 just came out a few days ago. Here are some useful installation tips.

Kobi answered 11/2, 2009 at 0:31 Comment(0)
B
0

I just use rdebug to debug any of my ruby or RoR code.

Bloat answered 27/9, 2008 at 17:23 Comment(0)
D
0

If you're willing to use an IDE for debugging, I know Eclipse (via the Ruby Development Tools) has a relatively straightforward interface. If you're doing rails then there's a specific build of eclipse called RadRails which may also help (though I haven't used it for debugging)

Delossantos answered 27/9, 2008 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.