Configure IRB¶ ↑
Configuration Sources¶ ↑
IRB configurations can be set through multiple sources, each with its own precedence:
-
Command-Line Options: When some options are specified when starting IRB, they can override default settings.
-
Configuration File: If present, IRB reads a configuration file containing Ruby code to set configurations.
-
Environment Variables: Certain environment variables influence IRB’s behavior.
-
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:
-
$IRBRC
-
$XDG_CONFIG_HOME/irb/irbrc
-
$HOME/.irbrc
-
$HOME/.config/irb/irbrc
-
.irbrc
in the current directory -
irb.rc
in the current directory -
_irbrc
in the current directory -
$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¶ ↑
-
NO_COLOR
: Disables IRB’s colorization. -
IRB_USE_AUTOCOMPLETE
: Setting tofalse
disables autocompletion. -
IRB_COMPLETOR
: Configures auto-completion behavior (regexp
ortype
). -
IRB_COPY_COMMAND
: Overrides the default program used to interface with the system clipboard. -
VISUAL
/EDITOR
: Specifies the editor for theedit
command. -
IRBRC
: Specifies the rc-file for configuration. -
XDG_CONFIG_HOME
: Used to locate the rc-file ifIRBRC
is unset. -
RI_PAGER
/PAGER
: Specifies the pager for documentation. -
IRB_LANG
,LC_MESSAGES
,LC_ALL
,LANG
: Determines the locale.
Hash IRB.conf
¶ ↑
The initial entries in hash IRB.conf
are determined by:
-
Default values.
-
Command-line options, which may override defaults.
-
Direct assignments in the configuration file.
You can see the hash by typing IRB.conf
. Below are the primary entries:
-
:AP_NAME
: IRB application name; initial value:'irb'
. -
:AT_EXIT
: Array of hooks to call at exit; initial value:[]
. -
:AUTO_INDENT
: Whether automatic indentation is enabled; initial value:true
. -
:BACK_TRACE_LIMIT
: Sets the back trace limit; initial value:16
. -
:COMMAND_ALIASES
: Defines input command aliases; initial value:{ "$": :show_source, "@": :whereami, }
-
:CONTEXT_MODE
: Sets the context mode, the type of binding to be used when evaluating statements; initial value:4
. -
:ECHO
: Whether to print (echo) return values; initial value:nil
, which would setconf.echo
totrue
. -
:ECHO_ON_ASSIGNMENT
: Whether to print (echo) return values on assignment; initial value:nil
, which would setconf.echo_on_assignment
to:truncate
. -
:EVAL_HISTORY
: How much evaluation history is to be stored; initial value:nil
. -
:EXTRA_DOC_DIRS
: Array of RI documentation directories to be parsed for the documentation dialog; initial value:[]
. -
:IGNORE_EOF
: Whether to ignore end-of-file; initial value:false
. -
:IGNORE_SIGINT
: Whether to ignore SIGINT; initial value:true
. -
:INSPECT_MODE
: Whether to use methodinspect
for printing (echoing) return values; initial value:true
. -
:IRB_LIB_PATH
: The path to the IRB library directory; initial value:-
"RUBY_DIR/lib/ruby/gems/RUBY_VER_NUM/gems/irb-IRB_VER_NUM/lib/irb"
,
where:
-
RUBY_DIR is the Ruby installation dirpath.
-
RUBY_VER_NUM is the Ruby version number.
-
IRB_VER_NUM is the IRB version number.
-
-
:IRB_NAME
: IRB name; initial value:'irb'
. -
:IRB_RC
: Configuration monitor; initial value:nil
. -
:LC_MESSAGES
: Locale; initial value: IRB::Locale object. -
:LOAD_MODULES
: deprecated. -
:MAIN_CONTEXT
: The context for the main IRB session; initial value:IRB::Context
object. -
:MEASURE
: Whether to measure performance; initial value:false
. -
:MEASURE_CALLBACKS
: Callback methods for performance measurement; initial value:[]
. -
:MEASURE_PROC
: Procs for performance measurement; initial value:{ :TIME=>#<Proc:0x0000556e271c6598 /var/lib/gems/3.0.0/gems/irb-1.8.3/lib/irb/init.rb:106>, :STACKPROF=>#<Proc:0x0000556e271c6548 /var/lib/gems/3.0.0/gems/irb-1.8.3/lib/irb/init.rb:116> }
-
:PROMPT
: Hash of defined prompts; initial value:{ :NULL=>{:PROMPT_I=>nil, :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>"%s\n"}, :DEFAULT=>{:PROMPT_I=>"%N(%m):%03n> ", :PROMPT_S=>"%N(%m):%03n%l ", :PROMPT_C=>"%N(%m):%03n* ", :RETURN=>"=> %s\n"}, :CLASSIC=>{:PROMPT_I=>"%N(%m):%03n:%i> ", :PROMPT_S=>"%N(%m):%03n:%i%l ", :PROMPT_C=>"%N(%m):%03n:%i* ", :RETURN=>"%s\n"}, :SIMPLE=>{:PROMPT_I=>">> ", :PROMPT_S=>"%l> ", :PROMPT_C=>"?> ", :RETURN=>"=> %s\n"}, :INF_RUBY=>{:PROMPT_I=>"%N(%m):%03n> ", :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>"%s\n", :AUTO_INDENT=>true}, :XMP=>{:PROMPT_I=>nil, :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>" ==>%s\n"} }
-
:PROMPT_MODE
: Name of current prompt; initial value::DEFAULT
. -
:RC
: Whether a configuration file was found and interpreted; initial value:true
if a configuration file was found,false
otherwise. -
:SAVE_HISTORY
: Number of commands to save in input command history; initial value:1000
. -
:SINGLE_IRB
: Whether command-line option--single-irb
was given; initial value:true
if the option was given,false
otherwise. See Single-IRB Mode. -
:USE_AUTOCOMPLETE
: Whether to use automatic completion; initial value:true
. -
:USE_COLORIZE
: Whether to use color highlighting; initial value:true
. -
:USE_LOADER
: Whether to use the IRB loader forrequire
andload
; initial value:false
. -
:USE_TRACER
: Whether to use the IRB tracer; initial value:false
. -
:VERBOSE
: Whether to print verbose output; initial value:nil
. -
:__MAIN__
: The main IRB object; initial value:main
.
Notes on Initialization Precedence¶ ↑
-
Any conflict between an entry in hash
IRB.conf
and a command-line option is resolved in favor of the hash entry. -
Hash
IRB.conf
affects the context only once, when the configuration file is interpreted; any subsequent changes to it do not affect the context and are therefore essentially meaningless.
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:
-
Command-line option
-r
$ irb -r csv -r json irb(main):001> conf.load_modules => ["csv", "json"]
-
Hash entry
IRB.conf[:LOAD_MODULES] = array
:IRB.conf[:LOAD_MODULES] = %w[csv json]
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:
-
Command-line option
--extra_doc_dir
$ irb --extra-doc-dir your_doc_dir --extra-doc-dir my_doc_dir irb(main):001> conf.extra_doc_dirs => ["your_doc_dir", "my_doc_dir"]
-
Hash entry
IRB.conf[:EXTRA_DOC_DIRS] = array
:IRB.conf[:EXTRA_DOC_DIRS] = %w[your_doc_dir my_doc_dir]
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
: