irb uses an initialization file in which you can set commonly used
options or execute any required Ruby statements. When irb is run, it
will try to load an initialization file from one of the following
sources in order:
~/.irbrc
,
.irbrc
,
irb.rc
,
_irbrc
, and
$irbrc
.
Within the initialization file you may run any arbitrary Ruby code.
You can also set any of the configuration values that correspond to
command-line arguments as shown in Table B.2 on page 518.
irb configuration values
|
IRB.conf[:IRB_NAME] = "irb"
|
IRB.conf[:MATH_MODE] = false
|
IRB.conf[:USE_TRACER] = false
|
IRB.conf[:USE_LOADER] = false
|
IRB.conf[:IGNORE_SIGINT] = true
|
IRB.conf[:IGNORE_EOF] = false
|
IRB.conf[:INSPECT_MODE] = nil
|
IRB.conf[:IRB_RC] = nil
|
IRB.conf[:BACK_TRACE_LIMIT] = 16
|
IRB.conf[:USE_LOADER] = false
|
IRB.conf[:USE_READLINE] = nil
|
IRB.conf[:USE_TRACER] = false
|
IRB.conf[:IGNORE_SIGINT] = true
|
IRB.conf[:IGNORE_EOF] = false
|
IRB.conf[:PROMPT_MODE] = :DEFAULT
|
IRB.conf[:PROMPT] = { ... }
|
IRB.conf[:DEBUG_LEVEL] = 0
|
IRB.conf[:VERBOSE] = true
|
|
|
As an interesting twist on configuring irb, you can set
IRB.conf[:IRB_RC]
to a
Proc
object. This proc will be
invoked whenever the irb context is changed, and will receive that new
context as a parameter. You can use this facility to change the
configuration dynamically based on the context.