Home > ruby > Using .irbrc file to configure your IRB

Using .irbrc file to configure your IRB

In my latest post “IRB Recipes” where we’ve discussed how to configure IRB to enable auto-complete, auto-indent and to clear screen, notice that when you exit your IRB the configurations return to its default value. And it not so DRY (Don’t Repeat Yourself) to type the recipes every time you fire up your IRB.

This prob leads us to using an .irbrc file to permanently configure your IRB every time you use it. Here’s how I set up my initial .irbrc file:

1. Create .irbrc or _irbrc file in wherever directory/location you want (In my case I saved it in C:\Documents and Settings\user)

Note: Creating a file in notepad/wordpad having “.” before the filename will not allow you to do so, I suggest you use Notepad++ source code editor

2. Edit your .irbrc file

.irbrc file

.irbrc file

Let’s dissect the .irbrc file configuration:

Line 1:  Enables auto-completion

Line 2:  Enables pretty print

Line 3:  Enables auto-indention

Line 4:  Enables the use of readline

Line 6-8:  Enables clear screen inside IRB

Line 9:  Validates if that .irbrc file was loaded successfully

3. Check if the your .irbrc file is successfully loaded

  • Run console
  • Go to the directory where you saved your .irbrc file
  • Fire up IRB
  • Manually check auto-indention, auto-completion and clear screen method (in my case I validated it with a “Yes! Configuration is loaded!” message)

4. To effect the .irbrc configuration in other directory other than its current location

  • Create a HOME environment variable name
  • Set variable value to the current location of the .irbrc file
  • Reboot to effect changes in the environment variable

5. Verify .irbrc file by going through step # 3 but this time go to other directory and not on the location of your .irbrc file

Categories: ruby Tags: , ,
  1. February 20, 2009 at 1:59 pm

    hahaha ayos to! galing!
    better try this one… pampadali ng buhay Selenium using irb…
    tnx girl! keep on posting! =D>

  2. jiimms
    May 14, 2015 at 1:23 pm

    great tip, Thanks. I have been struggling with this for the longest time. Total Newbie, couldnt figure out how to save the .ircbc file…got it now 🙂

  3. Krishnaveni Vempati
    June 29, 2015 at 12:52 am

    Thank you so much!!
    It really helped in understanding the concept.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: