Configure IRB

Configuration Sources

IRB configurations can be set through multiple sources, each with its own precedence:

  1. Command-Line Options: When some options are specified when starting IRB, they can override default settings.

  2. Configuration File: If present, IRB reads a configuration file containing Ruby code to set configurations.

  3. Environment Variables: Certain environment variables influence IRB’s behavior.

  4. Hash IRB.conf: This hash holds the current configuration settings, which can be modified during a session.

Configuration File Path Resolution

IRB searches for a configuration file in the following order:

  1. $IRBRC

  2. $XDG_CONFIG_HOME/irb/irbrc

  3. $HOME/.irbrc

  4. $HOME/.config/irb/irbrc

  5. .irbrc in the current directory

  6. irb.rc in the current directory

  7. _irbrc in the current directory

  8. $irbrc in the current directory

If the -f command-line option is used, no configuration file is loaded.

Method conf.rc? returns true if a configuration file was read, false otherwise. Hash entry IRB.conf[:RC] also contains that value.

Environment Variables

Hash IRB.conf

The initial entries in hash IRB.conf are determined by:

You can see the hash by typing IRB.conf. Below are the primary entries:

Notes on Initialization Precedence

Load Modules

You can specify the names of modules that are to be required at startup.

Array conf.load_modules determines the modules (if any) that are to be required during session startup. The array is used only during session startup, so the initial value is the only one that counts.

The default initial value is [] (load no modules):

irb(main):001> conf.load_modules
=> []

You can set the default initial value via:

Note that the configuration file entry overrides the command-line options.

RI Documentation Directories

You can specify the paths to RI documentation directories that are to be loaded (in addition to the default directories) at startup; see details about RI by typing ri --help.

Array conf.extra_doc_dirs determines the directories (if any) that are to be loaded during session startup. The array is used only during session startup, so the initial value is the only one that counts.

The default initial value is [] (load no extra documentation):

irb(main):001> conf.extra_doc_dirs
=> []

You can set the default initial value via:

Note that the configuration file entry overrides the command-line options.

IRB Name

You can specify a name for IRB.

The default initial value is 'irb':

irb(main):001> conf.irb_name
=> "irb"

You can set the default initial value via hash entry IRB.conf[:IRB_NAME] = string:

IRB.conf[:IRB_NAME] = 'foo'

Application Name

You can specify an application name for the IRB session.

The default initial value is 'irb':

irb(main):001> conf.ap_name
=> "irb"

You can set the default initial value via hash entry IRB.conf[:AP_NAME] = string:

IRB.conf[:AP_NAME] = 'my_ap_name'

Configuration Monitor

You can monitor changes to the configuration by assigning a proc to IRB.conf[:IRB_RC] in the configuration file:

IRB.conf[:IRB_RC] = proc {|conf| puts conf.class }

Each time the configuration is changed, that proc is called with argument conf: