How to enable auto completion in Ruby's IRB

RubyIrbTab Completion

Ruby Problem Overview


When I use Merb's built in console, I get tab auto-completion similar to a standard bash prompt. I find this useful and would like to enable it in non-merb IRB sessions. How do I get auto-completion in IRB?

Ruby Solutions


Solution 1 - Ruby

Just drop require 'irb/completion' in your irbrc.

If that doesn't work try bond, http://tagaholic.me/bond/:

   require 'bond'; require 'bond/completion'

Bond not only improves irb's completion, http://tagaholic.me/2009/07/22/better-irb-completion-with-bond.html, but also offers an easy dsl for making custom autocompletions.

Solution 2 - Ruby

This is just repeating the information on Cody Caughlan's comment above so it is easier to find:

either require 'irb/completion' or add the following to ~/.irbrc

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] = [] unless IRB.conf.key?(:LOAD_MODULES)
unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
  IRB.conf[:LOAD_MODULES] << 'irb/completion'
end 

Solution 3 - Ruby

This is what worked for me on Mac OS 10.11.5. using rvm. Do the following :

  1. sudo gem install bond
  2. Create the file .irbrc in your home directory. vi ~/.irbrc
  3. Add the following lines in the .irbrc file
require 'bond' 
Bond.start
  1. Save and close the file
  2. Open irb and use tab key to autocomplete

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn F. MillerView Question on Stackoverflow
Solution 1 - RubycldwalkerView Answer on Stackoverflow
Solution 2 - RubyJohn F. MillerView Answer on Stackoverflow
Solution 3 - RubyJosephView Answer on Stackoverflow