The Interactive Ruby Shell, or irb, is indispensable for trying out Ruby code rapidly, seeing what works and what’s elegant. But the defaults aren’t quite optimal.
Tab completion
It lacks tab completion by default. Having this available can save you a lot of time, especially as you are learning the language. To turn it on, simply add the option “-r irb/completion” to require that functionality. You can also add it to a running session by entering “require ‘irb/completion’”. After setting this you can press Tab after a dot following an object to see what methods are available for it (not all methods shown in image):

Now you can type the method you want to use from the list. You can also type part of a method name and press Tab to view matches on what you have so far.
Appearance
The default prompt can also be a little too wordy:
![]()
This shows the program name (always “irb(main)” for the irb command), the line number within said program, and the indentation level. This last value is incremented as you move into loops and other multi-line structures. If you don’t want this meta information, however, just call irb with the “–simple prompt” option:
![]()
Aliases
I combine the above customizations into two Bash aliases for simpler access. Just add the following to your ~/.bashrc:
1 2 | alias r="irb --simple-prompt -r irb/completion" alias irb="irb -r irb/completion" |
Now you can get to a simpler prompt for quick checks, or the full prompt for more complete documentation, making a tutorial, etc. And both have the lovely tab completion.
[EDIT, 2009-07-17]: As helpfully pointed out by commenter Vorian, the improvements above can also be attained using configuration options placed into ~/.irbrc. After hearing about this, I looked around for example .irbrc files and put together a decent one. Check out this post for more details.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.








why not just use an irbrc?
# Change the prompt
IRB.conf[:PROMPT_MODE] = :SIMPLE
@vorian Simply because I didn’t know it existed:-) Thanks for the tip!
Pingback: Improved irb configuration | tail -f findings.out