# Ruby Tip - IRB completion

**URL:** <https://www.ruby-forum.com/t/ruby-tip-irb-completion/61789>\
**Category:** Ruby\
**Created:** [May 27, 2006, 10:46am UTC](https://www.ruby-forum.com/t/ruby-tip-irb-completion/61789 "2006-05-27T10:46:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjohn\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@Benjohn\_B](https://www.ruby-forum.com/u/Benjohn_B)\
**Post date:** [May 27, 2006, 10:46am UTC](https://www.ruby-forum.com/t/ruby-tip-irb-completion/61789/1 "2006-05-27T10:46:28Z")

</div>

You can configure your IRB sessions to provide tab completion, and  
other neat things. A page here: [http://tinyurl.com/fkuj2](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

---

<div class="post-metadata">

**Author:** ![Benjohn\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@Benjohn\_B](https://www.ruby-forum.com/u/Benjohn_B)\
**Post date:** [May 27, 2006, 11:31am UTC](https://www.ruby-forum.com/t/ruby-tip-irb-completion/61789/2 "2006-05-27T11:31:37Z")

</div>

2006/5/27, Benjohn B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> You can configure your IRB sessions to provide tab completion, and  
> other neat things. A page here: [http://tinyurl.com/fkuj2](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

---

<div class="post-metadata">

**Author:** ![Benjohn\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@Benjohn\_B](https://www.ruby-forum.com/u/Benjohn_B)\
**Post date:** [May 27, 2006, 12:26pm UTC](https://www.ruby-forum.com/t/ruby-tip-irb-completion/61789/3 "2006-05-27T12:26:28Z")

</div>

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

> :-))
> 
> Kind regards
> 
> robert

🙂 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… 🙂 Although it makes absolutely no  
difference in the end, of course.

---

<div class="post-metadata">

**Author:** ![Benjohn\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@Benjohn\_B](https://www.ruby-forum.com/u/Benjohn_B)\
**Post date:** [May 27, 2006, 1:00pm UTC](https://www.ruby-forum.com/t/ruby-tip-irb-completion/61789/4 "2006-05-27T13:00:05Z")

</div>

2006/5/27, Benjohn B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > 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… 🙂 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
