Tab completion in irb


irb has tab completion support, you need to activate this by requiring ‘irb/completion’. You can load it when you invoke irb from the command line:


% irb -r irb/completion

Or you can load the completion library when irb is running:


% irb(main):005:0> require 'irb/completion'

If you often use tab completion then:

Linux users: Can create an alias in .bashrc by following these steps:

  • % vi ~/.bashrc
  • add alias irbtc="irb -r 'irb/completion'"
  • % source ~/.bashrc

Windows Users: Can create a file named irbtc.bat in your windows\system32 folder as irb -r “irb/completion” the file content.

<
Now you can run irb with tab completion support by:
% irbtc

Example:

% irbtc
irb(main):001:0> st="this is a string"
=> "this is a string"
irb(main):002:0> st.len
tab
irb(main):002:0> st.length
=> 16
irb(main):003:0> st.up
tabtab
st.upcase st.upcase! st.upto
irb(main):003:0> st.up

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
Ruby On Rails India
What do you see a face or an Eskimo?
If my code or post helps you then please recommend me at workingwithrails.com by clicking on button below:
Recommend Me

Reader Comments

or:

require 'irb/completion'

in your ~/.ircrc file

sorry, typo, that should of course be:

~/.irbrc

..and not:

~/.ircrc

how about just adding the require line to your .irbrc? No need to fuss with aliases or bashrc.

While you’re there, try requiring ‘pp’ for pretty printing, and maybe include this code for persistent command line history across irb sessions: http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks

I was getting some strange problem while starting webrick after adding require line in .irbrc file.

[...] A fast &#38; effective way for having auto-completion in irb (with some limitation) via web on rails [...]

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.