irb tab completion
May 7th, 2007 at 5:49 pmirb is the interactive Ruby shell – an incredibly useful tool during development. Lisp folks are proud of the REPL (Read-Evaluate-Print Loop) – well, irb is REPL for Ruby.
What turns irb into an even more useful instrument, however, is tab completion. First, it makes coding quicker by completing known symbols (kind of an Intellisense, if you’d like). Second, and more importantly, it allows you to quickly see which methods are implemented for objects, by typing:
irb(main):001:0> some_object.
And pressing TAB twice, irb will list all the methods.
For some reason, however, irb doesn’t come with tab completion out of the box. To set it up, you can create a batch file called irbb.bat, for instance, which calls:
irb -r irb/completion
And call that instead of irb. A simpler method, IMHO, is directly edit the irb.bat file in the Ruby installation bin/ directory to require irb/completion.
P.S: I describe Windows solutions. It should be very similar for Linux.
Related posts:

May 7th, 2007 at 23:05
Thanks for the tip!
):
To do this on my Mac I used:
$ vi .profile
add the following line to the end (shift+G, i for the non-vim-ers
alias irb=’irb -r irb/completion’
save & exit (:x)
$ . .profile
$ irb
We’ve got working tab completion! Didn’t test this on my Linux/FreeBSD-box yet, but it should be about the same.
May 7th, 2007 at 23:17
This and a few other IRB enhancements are bundled up in a Gem called wirble: http://pablotron.org/software/wirble/
May 7th, 2007 at 23:23
Good call. I’ve always found the list of methods on an object by using .methods. But no more! And this does more than just print the methods. Life’s Good.
Martin that does work on Linux. I tend to use bash functions but both work.
May 9th, 2007 at 03:12
Hey, why not just add the line
require 'irb/completion'to your~/.irbrcfile?May 9th, 2007 at 06:11
Where is the ~/.irbrc file on Windows ? (this is the system this post talks about)
May 10th, 2007 at 20:42
I guess irb just uses HOME environment variable to locate the .irbrc file, so you have to set up this variable if you don’t have it already, start the new cmd session and try it out.
May 15th, 2007 at 15:35
On OS X, with the default ruby install, this doesn’t work. There is no “irb/completion” file for the require to find. Anyone got a work-around?
August 15th, 2007 at 17:47
Thanks for your solution.
September 3rd, 2007 at 23:01
There’s quite a few more good editing tips for irb to be found at http://www.tortoiseandachilles.com/2007/09/improve-your-interactive-programming.html It’s amazing how much more useful irb is once you turn it into a decent editing environment. I use it constantly now, and Rails’ console as well.