TIP: Ruby, IRB Auto-Complete

Create/Edit the .irbrc file in your home directory (UNIX users) and add the following code:

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

Now, when you are typing commands into IRB, you can hit the “tab” key and it will automatically complete the command for you or display a list of possible commands.

6 Comments »

  1. include said,

    May 20, 2008 @ 7:42 pm

    nice add is:

    require ‘rubygems’
    require ‘wirble’

    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

    Wirble.init
    Wirble.colorize

    to get colors on it :P

  2. Vidul said,

    June 9, 2009 @ 4:54 am

    Thanks, both the post and the comment help a lot!

  3. include said,

    June 9, 2009 @ 9:03 am

    Thanks @Vidul :)

  4. MetalElf0 said,

    June 24, 2009 @ 7:57 am

    Thanks for the post, really helpful!

  5. DGM said,

    April 12, 2010 @ 10:29 am

    Nice work. Actually some additions on top:

    #!/usr/bin/ruby
    # coding: utf-8

    require ‘rubygems’
    require ‘wirble’

    # Include tab-completion in irb
    #require ‘irb/completion’

    #instead I choose Bond
    require ‘bond’
    require ‘bond/completion’

    rest is OK for me.
    3 Cheers :)

  6. include said,

    April 12, 2010 @ 10:49 am

    Hi DMG

    your tip sounds great. I will try out bond. [ http://github.com/cldwalker/bond ]

    looks like it’s a nice tool to have [ http://ruby-toolbox.com/categories/irb_tools.html ] it’s listed in the Ruby toolbox. :)

    have fun

    Cheers :)

RSS feed for comments on this post · TrackBack URI

Leave a Comment

Related Posts