Forum: Ruby Ruby Tip - IRB completion

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ffcb418e17cac2873d611c2b8d8d891c?d=identicon&s=25 Benjohn Barnes (Guest)
on 2006-05-27 10:46
(Received via mailing list)
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
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2006-05-27 11:31
(Received via mailing list)
2006/5/27, Benjohn Barnes <benjohn@fysh.org>:
> 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
Ffcb418e17cac2873d611c2b8d8d891c?d=identicon&s=25 Benjohn Barnes (Guest)
on 2006-05-27 12:26
(Received via mailing list)
On 27 May 2006, at 10:28, Robert Klemme 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.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2006-05-27 13:00
(Received via mailing list)
2006/5/27, Benjohn Barnes <benjohn@fysh.org>:
> >> 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
This topic is locked and can not be replied to.