Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

IRB: Let’s Bone Up On The Interactive Ruby Shell

By Peter Cooper / May 14, 2009

irbism.pngThe Interactive Ruby Shell, more commonly known as IRB, is one of Ruby's most popular features, especially with new developers. You can bash out a one-liner, try a method you've just learned about, or even build a small algorithm or two without going the whole way to writing a complete program.

I've not posted much about IRB before and it doesn't tend to get a lot of love generally, so while I've been digging through some of the best content I can find on IRB learning all about its internals and ways to get more out of it, I thought I should share:

Demystifying Irb's Commands - An awesome look at the hidden internals, special methods and features within IRB and the impetus for starting this post. Author Gabriel Horner looks at stuff like workspaces, subsessions, and IRB-specific loading methods.

What's Your Favorite IRB Trick? - A list of community-provided IRB tricks and tips on Stack Overflow. Of particular note is the first answer that covers the basic subsession commands (jobs, fg #, and kill #). There are also suggestions for easier benchmarking, predefined data, and using Wirble (mentioned below).

Utility Belt - A "grab-bag of tricks, tools, techniques, trifles, and toys for IRB." There's a ton of useful stuff in here for IRB power users and the feature list is longer than my arm: Amazon S3 support, "with" statement, history buffer, Pastie support, OS X clipboard support, external text editor support, auto-indentation, and more.

irb & script/console tips - A few useful IRB tips and resources from Thoughtbot's Dan Croak. Very practical and code driven. Dan advises loading pp (pretty printer) by default from your .irbrc file.

irb_rocket: An irb plugin - irb_rocket is an add-on for IRB that presents the result of your expression at the end of the current line in a "hash rocket" style.

Rails Console Tricks (screencast) - A screencast by Ryan Bates on the Rails console (a cousin of IRB) featuring a ton of useful tips, some of which are useful to IRB users generally.

Wirble: Tab-Completion and Syntax Coloring for irb - Wirble (homepage) is a Ruby library that adds a number of features to IRB. Of particular interest is its addition of syntax coloring. Install the wirble gem, add a few lines to your .irbrc file, and you get colored results in the data structures coming back from your IRB commands.

IRB documentation from the old Pickaxe - A lengthy page about IRB from the first edition of Programming Ruby (the Pickaxe). Not very up to date but sufficient for Ruby 1.8. Covers command line options, configuration files, and some of the special variables are commands available when running IRB.

Try Ruby - Not got Ruby installed or want to play in an IRB that's not your own? whytheluckystiff's Try Ruby is a great way to play with IRB through a Web browser. It includes an interactive tutorial, too.

Comments

  1. IRB Enthusiast says:

    Yeeeeah! It's time IRB got some love. It is, after all, the way most people get introduced to Ruby.

  2. AkitaOnRails says:

    Try my Utility Belt fork. It has some added bits that you may like: http://github.com/akitaonrails/utility-belt/tree.

  3. Giles Bowkett says:

    What's funny is, I paged down to the comments area to leave a comment about Akita's Utility Belt fork myself. First comment I see is the comment I was going to make.

    I've not been great about maintaining Utility Belt at all. Tim Connor also has a Utility Belt fork which I believe is superior to mine. ;-) I think the biggest improvement is that both these forks support Linux better than mine does.

  4. AkitaOnRails says:

    Just so people don't take it the wrong way. I just added minor bits. Giles utility belt is a great foundation to work in. I hope you have some more time to add even more :-)

  5. Soleone says:

    Windows users of utility_belt or wirble need to install the gem "win32console" to get the irb coloring, or else any output will contain unevaluated color codes, which make it hard to read return values.

    Just install the gem and require 'win32/console' in .irbrc. Unfortunately this causes issues when typing text anywhere but the end of the current line, but I can live with that. If anyone has a solution for this problem though I would be delighted to hear it.

  6. roger says:

    I have really liked irb fastri before:

    http://eigenclass.org/hiki/irb+ri+completion

  7. cldwalker says:

    Peter, glad to be an impetus for your irb explorations. I've written a second irb article in the same vein as the first which covers all of irb's configuration options: http://tagaholic.me/2009/05/29/exploring-how-to-configure-irb.html

Other Posts to Enjoy

Twitter Mentions