Ruby Tip - IRB completion

You can configure your IRB sessions to provide tab completion, and
other neat things. A page here: http://tinyurl.com/fkuj2 gives
details, but the code there can be improved with a few Ruby idioms.
Here’s what’s in mine:

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] ||= []
IRB.conf[:LOAD_MODULES] |= [‘irb/completion’]

Cheers,
Benjohn

2006/5/27, Benjohn B. [email protected]:

You can configure your IRB sessions to provide tab completion, and
other neat things. A page here: http://tinyurl.com/fkuj2 gives
details, but the code there can be improved with a few Ruby idioms.
Here’s what’s in mine:

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] ||= []
IRB.conf[:LOAD_MODULES] |= [‘irb/completion’]

If you’re in for simplifying you can have it even simpler

IRB.conf[:AUTO_INDENT] = IRB.conf[:USE_READLINE] = true
(IRB.conf[:LOAD_MODULES] ||= []) << [‘irb/completion’]

Even simpler, on my system (cygwin) it’s as simple as writing a single
line into ~/.irbrc:

$ cat .irbrc
require “irb/completion”

:-))

Kind regards

robert

On 27 May 2006, at 10:28, Robert K. wrote:

:-))

Kind regards

robert

:slight_smile: Thanks Robert. Cool that as “.irbrc” is just “required” by IRB at
start up, you can do anything you like in it, include requiring other
modules, as you do.

As you’re being really smart though, I’m going to point out that
(IRB.conf[:LOAD_MODULES] ||= []) << [‘irb/completion’]

isn’t equivalent to
IRB.conf[:LOAD_MODULES] ||= []
IRB.conf[:LOAD_MODULES] |= [‘irb/completion’]

…the latter will ensure only one attempt is made to load the
“completion” module, and it’ll prevent the array getting cluttered up
if you look at it later on… :slight_smile: Although it makes absolutely no
difference in the end, of course.

2006/5/27, Benjohn B. [email protected]:

IRB.conf[:USE_READLINE] = true

start up, you can do anything you like in it, include requiring other
“completion” module, and it’ll prevent the array getting cluttered up
if you look at it later on… :slight_smile: Although it makes absolutely no
difference in the end, of course.

My bad. You’re right of course, I didn’t finish the copy, paste and
mody process properly. That should of course have read

(IRB.conf[:LOAD_MODULES] ||= []) << ‘irb/completion’

Still you might get duplicate entries but that doesn’t matter that
much here - as you said already.

Thanks for pointing it out!

Kind regards

robert