irb 1.15.1 → 1.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rdoc_options +5 -0
- data/CONTRIBUTING.md +52 -0
- data/EXTEND_IRB.md +3 -0
- data/Gemfile +2 -0
- data/doc/COMMAND_LINE_OPTIONS.md +69 -0
- data/doc/COMPARED_WITH_PRY.md +22 -0
- data/doc/Configurations.md +275 -0
- data/doc/EXTEND_IRB.md +122 -0
- data/doc/Index.md +705 -0
- data/lib/irb/completion.rb +31 -36
- data/lib/irb/debug.rb +2 -2
- data/lib/irb/easter-egg.rb +3 -1
- data/lib/irb/input-method.rb +17 -11
- data/lib/irb/inspector.rb +1 -1
- data/lib/irb/pager.rb +1 -1
- data/lib/irb/ruby-lex.rb +25 -0
- data/lib/irb/source_finder.rb +1 -1
- data/lib/irb/version.rb +2 -2
- data/lib/irb.rb +36 -16
- metadata +11 -7
- data/Rakefile +0 -52
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/irb.gemspec +0 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c3e1957674939d29308f3f534aa65b0a85557c1b7cd47ca6709fef260486eba
|
|
4
|
+
data.tar.gz: f60b6b8752639425dc0e8aec1443fdc88b82c9799e6c71edf4dd88945efbbd23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc15c91bd69233b5cbe962cec327c918805db5553c81c4ba450836d626ab56a3745fd04ca4e185470434bd1e69fe94bab9536bf3bf4704538bbf39681b2291ac
|
|
7
|
+
data.tar.gz: 4b655b0a770eb2524757b8033e5796892dd43944ee7157dd7523f31d4fe6ffe6fed49ca281faa4990ba2c0dd014e662b1fc54445ee80ea5aa135cf097102d005
|
data/.rdoc_options
ADDED
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Contributing to IRB
|
|
2
|
+
|
|
3
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/ruby/irb](https://github.com/ruby/irb).
|
|
4
|
+
|
|
5
|
+
## Set up the environment
|
|
6
|
+
|
|
7
|
+
1. Fork the project to your GitHub account.
|
|
8
|
+
2. Clone the fork with `git clone git@github.com:[your_username]/irb.git`.
|
|
9
|
+
3. Run `bundle install`.
|
|
10
|
+
4. Run `bundle exec rake` to make sure tests pass locally.
|
|
11
|
+
|
|
12
|
+
## Run integration tests
|
|
13
|
+
|
|
14
|
+
If your changes affect component rendering, such as the autocompletion's dialog/dropdown, you may need to run IRB's integration tests, known as `yamatanooroti`.
|
|
15
|
+
|
|
16
|
+
Before running these tests, ensure that you have `libvterm` installed. If you're using Homebrew, you can install it by running:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
brew install libvterm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
After installing `libvterm`, you can run the integration tests using the following commands:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
WITH_VTERM=1 bundle install
|
|
26
|
+
WITH_VTERM=1 bundle exec rake test test_yamatanooroti
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Update documentation
|
|
30
|
+
|
|
31
|
+
IRB's documentation is generated by [RDoc](https://ruby.github.io/rdoc/) and published to [ruby.github.io/irb](https://ruby.github.io/irb/). Most of the documentation source lives under the `doc/` directory.
|
|
32
|
+
|
|
33
|
+
Run the following command to generate the documentation site locally.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bundle exec rake rdoc
|
|
37
|
+
bundle exec rake rerdoc # to force regeneration
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Follow the output message to open the documentation site in your browser.
|
|
41
|
+
|
|
42
|
+
> [!Note]
|
|
43
|
+
>
|
|
44
|
+
> Please ensure that the changes are rendered correctly on the documentation site.
|
|
45
|
+
> RDoc's Markdown support is limited, so the rendered result on GitHub might differ from what’s rendered on [https://ruby.github.io/irb](https://ruby.github.io/irb).
|
|
46
|
+
|
|
47
|
+
We welcome any improvements to the documentation, including:
|
|
48
|
+
|
|
49
|
+
- Fixing typos and grammatical errors.
|
|
50
|
+
- Adding missing documentation for features.
|
|
51
|
+
- Adding missing documentation for configuration options.
|
|
52
|
+
- Adding demo images/gifs for features.
|
data/EXTEND_IRB.md
ADDED
data/Gemfile
CHANGED
|
@@ -25,5 +25,7 @@ gem "debug", github: "ruby/debug", platforms: [:mri, :mswin]
|
|
|
25
25
|
gem "rdoc", ">= 6.11.0"
|
|
26
26
|
|
|
27
27
|
if RUBY_VERSION >= "3.0.0" && !is_truffleruby
|
|
28
|
+
# TODO: Remove this after rbs is released with tsort in its dependencies
|
|
29
|
+
gem "rbs", github: "ruby/rbs" if RUBY_VERSION >= "3.2"
|
|
28
30
|
gem "repl_type_completor"
|
|
29
31
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Index of Command-Line Options
|
|
2
|
+
|
|
3
|
+
These are the IRB command-line options, with links to explanatory text:
|
|
4
|
+
|
|
5
|
+
- `-d`: Set `$DEBUG` and {$VERBOSE}[rdoc-ref:IRB@Verbosity]
|
|
6
|
+
to `true`.
|
|
7
|
+
- `-E _ex_[:_in_]`: Set initial external (ex) and internal (in)
|
|
8
|
+
{encodings}[rdoc-ref:IRB@Encodings] (same as `ruby -E`).
|
|
9
|
+
- `-f`: Don't initialize from {configuration file}[rdoc-ref:IRB@Configuration+File].
|
|
10
|
+
- `-I _dirpath_`: Specify {$LOAD_PATH directory}[rdoc-ref:IRB@Load+Modules]
|
|
11
|
+
(same as `ruby -I`).
|
|
12
|
+
- `-r _load-module_`: Require {load-module}[rdoc-ref:IRB@Load+Modules]
|
|
13
|
+
(same as `ruby -r`).
|
|
14
|
+
- `-U`: Set external and internal {encodings}[rdoc-ref:IRB@Encodings] to UTF-8.
|
|
15
|
+
- `-w`: Suppress {warnings}[rdoc-ref:IRB@Warnings] (same as `ruby -w`).
|
|
16
|
+
- `-W[_level_]`: Set {warning level}[rdoc-ref:IRB@Warnings];
|
|
17
|
+
0=silence, 1=medium, 2=verbose (same as `ruby -W`).
|
|
18
|
+
- `--autocomplete`: Use {auto-completion}[rdoc-ref:IRB@Automatic+Completion].
|
|
19
|
+
- `--back-trace-limit _n_`: Set a {backtrace limit}[rdoc-ref:IRB@Tracer];
|
|
20
|
+
display at most the top `n` and bottom `n` entries.
|
|
21
|
+
- `--colorize`: Use {color-highlighting}[rdoc-ref:IRB@Color+Highlighting]
|
|
22
|
+
for input and output.
|
|
23
|
+
- `--context-mode _n_`: Select method to create Binding object
|
|
24
|
+
for new {workspace}[rdoc-ref:IRB@Commands]; `n` in range `0..4`.
|
|
25
|
+
- `--echo`: Print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
26
|
+
return values.
|
|
27
|
+
- `--extra-doc-dir _dirpath_`:
|
|
28
|
+
Add a {documentation directory}[rdoc-ref:IRB@RI+Documentation+Directories]
|
|
29
|
+
for the documentation dialog.
|
|
30
|
+
- `--inf-ruby-mode`: Set prompt mode to {:INF_RUBY}[rdoc-ref:IRB@Pre-Defined+Prompts]
|
|
31
|
+
(appropriate for `inf-ruby-mode` on Emacs);
|
|
32
|
+
suppresses --multiline and --singleline.
|
|
33
|
+
- `--inspect`: Use method `inspect` for printing ({echoing}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
34
|
+
return values.
|
|
35
|
+
- `--multiline`: Use the multiline editor as the {input method}[rdoc-ref:IRB@Input+Method].
|
|
36
|
+
- `--noautocomplete`: Don't use {auto-completion}[rdoc-ref:IRB@Automatic+Completion].
|
|
37
|
+
- `--nocolorize`: Don't use {color-highlighting}[rdoc-ref:IRB@Color+Highlighting]
|
|
38
|
+
for input and output.
|
|
39
|
+
- `--noecho`: Don't print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
40
|
+
return values.
|
|
41
|
+
- `--noecho-on-assignment`: Don't print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
42
|
+
result on assignment.
|
|
43
|
+
- `--noinspect`: Don't se method `inspect` for printing ({echoing}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
44
|
+
return values.
|
|
45
|
+
- `--nomultiline`: Don't use the multiline editor as the {input method}[rdoc-ref:IRB@Input+Method].
|
|
46
|
+
- `--noprompt`: Don't print {prompts}[rdoc-ref:IRB@Prompt+and+Return+Formats].
|
|
47
|
+
- `--noscript`: Treat the first command-line argument as a normal
|
|
48
|
+
{command-line argument}[rdoc-ref:IRB@Initialization+Script],
|
|
49
|
+
and include it in `ARGV`.
|
|
50
|
+
- `--nosingleline`: Don't use the singleline editor as the {input method}[rdoc-ref:IRB@Input+Method].
|
|
51
|
+
- `--noverbose`: Don't print {verbose}[rdoc-ref:IRB@Verbosity] details.
|
|
52
|
+
- `--prompt _mode_`, `--prompt-mode _mode_`:
|
|
53
|
+
Set {prompt and return formats}[rdoc-ref:IRB@Prompt+and+Return+Formats];
|
|
54
|
+
`mode` may be a {pre-defined prompt}[rdoc-ref:IRB@Pre-Defined+Prompts]
|
|
55
|
+
or the name of a {custom prompt}[rdoc-ref:IRB@Custom+Prompts].
|
|
56
|
+
- `--script`: Treat the first command-line argument as the path to an
|
|
57
|
+
{initialization script}[rdoc-ref:IRB@Initialization+Script],
|
|
58
|
+
and omit it from `ARGV`.
|
|
59
|
+
- `--simple-prompt`, `--sample-book-mode`:
|
|
60
|
+
Set prompt mode to {:SIMPLE}[rdoc-ref:IRB@Pre-Defined+Prompts].
|
|
61
|
+
- `--singleline`: Use the singleline editor as the {input method}[rdoc-ref:IRB@Input+Method].
|
|
62
|
+
- `--tracer`: Use {Tracer}[rdoc-ref:IRB@Tracer] to print a stack trace for each input command.
|
|
63
|
+
- `--truncate-echo-on-assignment`: Print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
64
|
+
truncated result on assignment.
|
|
65
|
+
- `--verbose`Print {verbose}[rdoc-ref:IRB@Verbosity] details.
|
|
66
|
+
- `-v`, `--version`: Print the {IRB version}[rdoc-ref:IRB@Version].
|
|
67
|
+
- `-h`, `--help`: Print the {IRB help text}[rdoc-ref:IRB@Help].
|
|
68
|
+
- `--`: Separate options from {arguments}[rdoc-ref:IRB@Command-Line+Arguments]
|
|
69
|
+
on the command-line.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Comparison with Pry
|
|
2
|
+
|
|
3
|
+
👋 IRB is on a mission to match feature parity with Pry. This document is here to help us track the similarities and differences between the two.
|
|
4
|
+
|
|
5
|
+
Feel free to chip in and update this table - we appreciate your help!
|
|
6
|
+
|
|
7
|
+
| Feature | Pry | IRB | Note |
|
|
8
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
|
|
9
|
+
| Supported Rubies | `>= 2.0` | `>= 2.7` | |
|
|
10
|
+
| Source code browsing | `show-source` | `show_source` | IRB's `show_source` can't display C source. See [#664](https://github.com/ruby/irb/issues/664) |
|
|
11
|
+
| Document browsing | `ri` | `show_doc` | |
|
|
12
|
+
| Live help system | `help` or `command_name --help` | `help` | IRB doesn't support detailed descriptions for individual commands yet |
|
|
13
|
+
| Open methods in editors | `edit` | `edit` | |
|
|
14
|
+
| Syntax highlighting | Yes | Yes | |
|
|
15
|
+
| Command shell integration | Yes | No | Currently, there's no plan to support such features in IRB |
|
|
16
|
+
| Navigation | - `cd object` to enter `object` <br/> - `cd ..` to leave the current object <br/> - `nesting` to list nesting levels | - `pushws object` <br/> - `popws` <br/> - `workspaces` <br /> - `cd object`/`cd ..` (since [1.14.0](https://github.com/ruby/irb/releases/tag/v1.14.0)) | We plan to refine IRB's commands in the future |
|
|
17
|
+
| Runtime invocation | `binding.pry` | `binding.irb` | |
|
|
18
|
+
| Command system | Yes | No | Planned in #513 and #588 |
|
|
19
|
+
| Input history | [Comprehensive support](https://github.com/pry/pry/wiki/History) | Supports retrieving previous input and the `history` command | The history command doesn't support as many flags yet, but contributions are welcome. |
|
|
20
|
+
| Pager support | Command output and return value | Command output and return value | |
|
|
21
|
+
| Debugger integration | With `byebug` through [pry-byebug](https://github.com/deivid-rodriguez/pry-byebug) gem | Supports [`irb:rdbg`](https://github.com/ruby/irb#debugging-with-irb) sessions | |
|
|
22
|
+
| Rails console | Through [`pry-rails`](https://github.com/pry/pry-rails) gem | Rails' default | Rails console with IRB doesn't have commands like `show-routes` or `show-models` |
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# Configure IRB
|
|
2
|
+
|
|
3
|
+
## Configuration Sources
|
|
4
|
+
|
|
5
|
+
IRB configurations can be set through multiple sources, each with its own precedence:
|
|
6
|
+
|
|
7
|
+
1. **Command-Line Options**: When some options are specified when starting IRB, they can override default settings.
|
|
8
|
+
2. **Configuration File**: If present, IRB reads a configuration file containing Ruby code to set configurations.
|
|
9
|
+
3. **Environment Variables**: Certain environment variables influence IRB's behavior.
|
|
10
|
+
4. **Hash `IRB.conf`**: This hash holds the current configuration settings, which can be modified during a session.
|
|
11
|
+
|
|
12
|
+
### Configuration File Path Resolution
|
|
13
|
+
|
|
14
|
+
IRB searches for a configuration file in the following order:
|
|
15
|
+
|
|
16
|
+
1. `$IRBRC`
|
|
17
|
+
2. `$XDG_CONFIG_HOME/irb/irbrc`
|
|
18
|
+
3. `$HOME/.irbrc`
|
|
19
|
+
4. `$HOME/.config/irb/irbrc`
|
|
20
|
+
5. `.irbrc` in the current directory
|
|
21
|
+
6. `irb.rc` in the current directory
|
|
22
|
+
7. `_irbrc` in the current directory
|
|
23
|
+
8. `$irbrc` in the current directory
|
|
24
|
+
|
|
25
|
+
If the `-f` command-line option is used, no configuration file is loaded.
|
|
26
|
+
|
|
27
|
+
Method `conf.rc?` returns `true` if a configuration file was read, `false` otherwise. Hash entry `IRB.conf[:RC]` also contains that value.
|
|
28
|
+
|
|
29
|
+
## Environment Variables
|
|
30
|
+
|
|
31
|
+
- `NO_COLOR`: Disables IRB's colorization.
|
|
32
|
+
- `IRB_USE_AUTOCOMPLETE`: Setting to `false` disables autocompletion.
|
|
33
|
+
- `IRB_COMPLETOR`: Configures auto-completion behavior (`regexp` or `type`).
|
|
34
|
+
- `IRB_COPY_COMMAND`: Overrides the default program used to interface with the system clipboard.
|
|
35
|
+
- `VISUAL` / `EDITOR`: Specifies the editor for the `edit` command.
|
|
36
|
+
- `IRBRC`: Specifies the rc-file for configuration.
|
|
37
|
+
- `XDG_CONFIG_HOME`: Used to locate the rc-file if `IRBRC` is unset.
|
|
38
|
+
- `RI_PAGER` / `PAGER`: Specifies the pager for documentation.
|
|
39
|
+
- `IRB_LANG`, `LC_MESSAGES`, `LC_ALL`, `LANG`: Determines the locale.
|
|
40
|
+
|
|
41
|
+
## Hash `IRB.conf`
|
|
42
|
+
|
|
43
|
+
The initial entries in hash `IRB.conf` are determined by:
|
|
44
|
+
|
|
45
|
+
- Default values.
|
|
46
|
+
- Command-line options, which may override defaults.
|
|
47
|
+
- Direct assignments in the configuration file.
|
|
48
|
+
|
|
49
|
+
You can see the hash by typing `IRB.conf`. Below are the primary entries:
|
|
50
|
+
|
|
51
|
+
- `:AP_NAME`: IRB {application name}[rdoc-ref:IRB@Application+Name];
|
|
52
|
+
initial value: `'irb'`.
|
|
53
|
+
- `:AT_EXIT`: Array of hooks to call
|
|
54
|
+
{at exit}[rdoc-ref:IRB@IRB];
|
|
55
|
+
initial value: `[]`.
|
|
56
|
+
- `:AUTO_INDENT`: Whether {automatic indentation}[rdoc-ref:IRB@Automatic+Indentation]
|
|
57
|
+
is enabled; initial value: `true`.
|
|
58
|
+
- `:BACK_TRACE_LIMIT`: Sets the {back trace limit}[rdoc-ref:IRB@Tracer];
|
|
59
|
+
initial value: `16`.
|
|
60
|
+
- `:COMMAND_ALIASES`: Defines input {command aliases}[rdoc-ref:IRB@Command+Aliases];
|
|
61
|
+
initial value:
|
|
62
|
+
|
|
63
|
+
{
|
|
64
|
+
"$": :show_source,
|
|
65
|
+
"@": :whereami,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
- `:CONTEXT_MODE`: Sets the {context mode}[rdoc-ref:IRB@Context+Mode],
|
|
69
|
+
the type of binding to be used when evaluating statements;
|
|
70
|
+
initial value: `4`.
|
|
71
|
+
- `:ECHO`: Whether to print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
72
|
+
return values;
|
|
73
|
+
initial value: `nil`, which would set `conf.echo` to `true`.
|
|
74
|
+
- `:ECHO_ON_ASSIGNMENT`: Whether to print ({echo}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29])
|
|
75
|
+
return values on assignment;
|
|
76
|
+
initial value: `nil`, which would set `conf.echo_on_assignment` to `:truncate`.
|
|
77
|
+
- `:EVAL_HISTORY`: How much {evaluation history}[rdoc-ref:IRB@Evaluation+History]
|
|
78
|
+
is to be stored; initial value: `nil`.
|
|
79
|
+
- `:EXTRA_DOC_DIRS`: Array of
|
|
80
|
+
{RI documentation directories}[rdoc-ref:IRB@RI+Documentation+Directories]
|
|
81
|
+
to be parsed for the documentation dialog;
|
|
82
|
+
initial value: `[]`.
|
|
83
|
+
- `:IGNORE_EOF`: Whether to ignore {end-of-file}[rdoc-ref:IRB@End-of-File];
|
|
84
|
+
initial value: `false`.
|
|
85
|
+
- `:IGNORE_SIGINT`: Whether to ignore {SIGINT}[rdoc-ref:IRB@SIGINT];
|
|
86
|
+
initial value: `true`.
|
|
87
|
+
- `:INSPECT_MODE`: Whether to use method `inspect` for printing
|
|
88
|
+
({echoing}[rdoc-ref:IRB@Return-Value+Printing+-28Echoing-29]) return values;
|
|
89
|
+
initial value: `true`.
|
|
90
|
+
- `:IRB_LIB_PATH`: The path to the {IRB library directory}[rdoc-ref:IRB@IRB+Library+Directory]; initial value:
|
|
91
|
+
|
|
92
|
+
- `"<i>RUBY_DIR</i>/lib/ruby/gems/<i>RUBY_VER_NUM</i>/gems/irb-<i>IRB_VER_NUM</i>/lib/irb"`,
|
|
93
|
+
|
|
94
|
+
where:
|
|
95
|
+
|
|
96
|
+
- <i>RUBY_DIR</i> is the Ruby installation dirpath.
|
|
97
|
+
- <i>RUBY_VER_NUM</i> is the Ruby version number.
|
|
98
|
+
- <i>IRB_VER_NUM</i> is the IRB version number.
|
|
99
|
+
|
|
100
|
+
- `:IRB_NAME`: {IRB name}[rdoc-ref:IRB@IRB+Name];
|
|
101
|
+
initial value: `'irb'`.
|
|
102
|
+
- `:IRB_RC`: {Configuration monitor}[rdoc-ref:IRB@Configuration+Monitor];
|
|
103
|
+
initial value: `nil`.
|
|
104
|
+
- `:LC_MESSAGES`: {Locale}[rdoc-ref:IRB@Locale];
|
|
105
|
+
initial value: IRB::Locale object.
|
|
106
|
+
- `:LOAD_MODULES`: deprecated.
|
|
107
|
+
- `:MAIN_CONTEXT`: The {context}[rdoc-ref:IRB@Session+Context] for the main IRB session;
|
|
108
|
+
initial value: IRB::Context object.
|
|
109
|
+
- `:MEASURE`: Whether to
|
|
110
|
+
{measure performance}[rdoc-ref:IRB@Performance+Measurement];
|
|
111
|
+
initial value: `false`.
|
|
112
|
+
- `:MEASURE_CALLBACKS`: Callback methods for
|
|
113
|
+
{performance measurement}[rdoc-ref:IRB@Performance+Measurement];
|
|
114
|
+
initial value: `[]`.
|
|
115
|
+
- `:MEASURE_PROC`: Procs for
|
|
116
|
+
{performance measurement}[rdoc-ref:IRB@Performance+Measurement];
|
|
117
|
+
initial value:
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
:TIME=>#<Proc:0x0000556e271c6598 /var/lib/gems/3.0.0/gems/irb-1.8.3/lib/irb/init.rb:106>,
|
|
121
|
+
:STACKPROF=>#<Proc:0x0000556e271c6548 /var/lib/gems/3.0.0/gems/irb-1.8.3/lib/irb/init.rb:116>
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
- `:PROMPT`: Hash of {defined prompts}[rdoc-ref:IRB@Prompt+and+Return+Formats];
|
|
125
|
+
initial value:
|
|
126
|
+
|
|
127
|
+
{
|
|
128
|
+
:NULL=>{:PROMPT_I=>nil, :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>"%s\n"},
|
|
129
|
+
:DEFAULT=>{:PROMPT_I=>"%N(%m):%03n> ", :PROMPT_S=>"%N(%m):%03n%l ", :PROMPT_C=>"%N(%m):%03n* ", :RETURN=>"=> %s\n"},
|
|
130
|
+
:CLASSIC=>{:PROMPT_I=>"%N(%m):%03n:%i> ", :PROMPT_S=>"%N(%m):%03n:%i%l ", :PROMPT_C=>"%N(%m):%03n:%i* ", :RETURN=>"%s\n"},
|
|
131
|
+
:SIMPLE=>{:PROMPT_I=>">> ", :PROMPT_S=>"%l> ", :PROMPT_C=>"?> ", :RETURN=>"=> %s\n"},
|
|
132
|
+
:INF_RUBY=>{:PROMPT_I=>"%N(%m):%03n> ", :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>"%s\n", :AUTO_INDENT=>true},
|
|
133
|
+
:XMP=>{:PROMPT_I=>nil, :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>" ==>%s\n"}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
- `:PROMPT_MODE`: Name of {current prompt}[rdoc-ref:IRB@Prompt+and+Return+Formats];
|
|
137
|
+
initial value: `:DEFAULT`.
|
|
138
|
+
- `:RC`: Whether a {configuration file}[rdoc-ref:IRB@Configuration+File]
|
|
139
|
+
was found and interpreted;
|
|
140
|
+
initial value: `true` if a configuration file was found, `false` otherwise.
|
|
141
|
+
- `:SAVE_HISTORY`: Number of commands to save in
|
|
142
|
+
{input command history}[rdoc-ref:IRB@Input+Command+History];
|
|
143
|
+
initial value: `1000`.
|
|
144
|
+
- `:SINGLE_IRB`: Whether command-line option `--single-irb` was given;
|
|
145
|
+
initial value: `true` if the option was given, `false` otherwise.
|
|
146
|
+
See {Single-IRB Mode}[rdoc-ref:IRB@Single-IRB+Mode].
|
|
147
|
+
- `:USE_AUTOCOMPLETE`: Whether to use
|
|
148
|
+
{automatic completion}[rdoc-ref:IRB@Automatic+Completion];
|
|
149
|
+
initial value: `true`.
|
|
150
|
+
- `:USE_COLORIZE`: Whether to use
|
|
151
|
+
{color highlighting}[rdoc-ref:IRB@Color+Highlighting];
|
|
152
|
+
initial value: `true`.
|
|
153
|
+
- `:USE_LOADER`: Whether to use the
|
|
154
|
+
{IRB loader}[rdoc-ref:IRB@IRB+Loader] for `require` and `load`;
|
|
155
|
+
initial value: `false`.
|
|
156
|
+
- `:USE_TRACER`: Whether to use the
|
|
157
|
+
{IRB tracer}[rdoc-ref:IRB@Tracer];
|
|
158
|
+
initial value: `false`.
|
|
159
|
+
- `:USE_PAGER`: Controls whether pager is enabled.
|
|
160
|
+
initial value: `true`.
|
|
161
|
+
- `:VERBOSE`: Whether to print {verbose output}[rdoc-ref:IRB@Verbosity];
|
|
162
|
+
initial value: `nil`.
|
|
163
|
+
- `:__MAIN__`: The main IRB object;
|
|
164
|
+
initial value: `main`.
|
|
165
|
+
|
|
166
|
+
## Notes on Initialization Precedence
|
|
167
|
+
|
|
168
|
+
- Any conflict between an entry in hash `IRB.conf` and a command-line option is resolved in favor of the hash entry.
|
|
169
|
+
- 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.
|
|
170
|
+
|
|
171
|
+
## Load Modules
|
|
172
|
+
|
|
173
|
+
You can specify the names of modules that are to be required at startup.
|
|
174
|
+
|
|
175
|
+
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.
|
|
176
|
+
|
|
177
|
+
The default initial value is `[]` (load no modules):
|
|
178
|
+
|
|
179
|
+
```console
|
|
180
|
+
irb(main):001> conf.load_modules
|
|
181
|
+
=> []
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
You can set the default initial value via:
|
|
185
|
+
|
|
186
|
+
- Command-line option `-r`
|
|
187
|
+
|
|
188
|
+
```console
|
|
189
|
+
$ irb -r csv -r json
|
|
190
|
+
irb(main):001> conf.load_modules
|
|
191
|
+
=> ["csv", "json"]
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
- Hash entry `IRB.conf[:LOAD_MODULES] = *array*`:
|
|
195
|
+
|
|
196
|
+
```ruby
|
|
197
|
+
IRB.conf[:LOAD_MODULES] = %w[csv json]
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Note that the configuration file entry overrides the command-line options.
|
|
201
|
+
|
|
202
|
+
## RI Documentation Directories
|
|
203
|
+
|
|
204
|
+
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`.
|
|
205
|
+
|
|
206
|
+
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.
|
|
207
|
+
|
|
208
|
+
The default initial value is `[]` (load no extra documentation):
|
|
209
|
+
|
|
210
|
+
```console
|
|
211
|
+
irb(main):001> conf.extra_doc_dirs
|
|
212
|
+
=> []
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
You can set the default initial value via:
|
|
216
|
+
|
|
217
|
+
- Command-line option `--extra_doc_dir`
|
|
218
|
+
|
|
219
|
+
```console
|
|
220
|
+
$ irb --extra-doc-dir your_doc_dir --extra-doc-dir my_doc_dir
|
|
221
|
+
irb(main):001> conf.extra_doc_dirs
|
|
222
|
+
=> ["your_doc_dir", "my_doc_dir"]
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
- Hash entry `IRB.conf[:EXTRA_DOC_DIRS] = *array*`:
|
|
226
|
+
|
|
227
|
+
```ruby
|
|
228
|
+
IRB.conf[:EXTRA_DOC_DIRS] = %w[your_doc_dir my_doc_dir]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Note that the configuration file entry overrides the command-line options.
|
|
232
|
+
|
|
233
|
+
## IRB Name
|
|
234
|
+
|
|
235
|
+
You can specify a name for IRB.
|
|
236
|
+
|
|
237
|
+
The default initial value is `'irb'`:
|
|
238
|
+
|
|
239
|
+
```console
|
|
240
|
+
irb(main):001> conf.irb_name
|
|
241
|
+
=> "irb"
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
You can set the default initial value via hash entry `IRB.conf[:IRB_NAME] = *string*`:
|
|
245
|
+
|
|
246
|
+
```ruby
|
|
247
|
+
IRB.conf[:IRB_NAME] = 'foo'
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Application Name
|
|
251
|
+
|
|
252
|
+
You can specify an application name for the IRB session.
|
|
253
|
+
|
|
254
|
+
The default initial value is `'irb'`:
|
|
255
|
+
|
|
256
|
+
```console
|
|
257
|
+
irb(main):001> conf.ap_name
|
|
258
|
+
=> "irb"
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
You can set the default initial value via hash entry `IRB.conf[:AP_NAME] = *string*`:
|
|
262
|
+
|
|
263
|
+
```ruby
|
|
264
|
+
IRB.conf[:AP_NAME] = 'my_ap_name'
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Configuration Monitor
|
|
268
|
+
|
|
269
|
+
You can monitor changes to the configuration by assigning a proc to `IRB.conf[:IRB_RC]` in the configuration file:
|
|
270
|
+
|
|
271
|
+
```console
|
|
272
|
+
IRB.conf[:IRB_RC] = proc {|conf| puts conf.class }
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Each time the configuration is changed, that proc is called with argument `conf`:
|
data/doc/EXTEND_IRB.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Extend IRB
|
|
2
|
+
|
|
3
|
+
From v1.13.0, IRB provides official APIs to extend its functionality. This feature allows libraries to
|
|
4
|
+
customize and enhance their users' IRB sessions by adding new commands and helper methods tailored for
|
|
5
|
+
the libraries.
|
|
6
|
+
|
|
7
|
+
## Helper Methods vs. Commands
|
|
8
|
+
|
|
9
|
+
- Use a helper method if the operation is meant to return a Ruby object that interacts with the application.
|
|
10
|
+
- For example, an `admin_user` helper method that returns `User.where(admin: true).first`, which can then be used like `login_as(admin_user)`.
|
|
11
|
+
- Use a command if the operation fits one of the following:
|
|
12
|
+
- A utility operation that performs non-Ruby related tasks, such as IRB's `edit` command.
|
|
13
|
+
- Displays information, like the `show_source` command.
|
|
14
|
+
- If the operation requires non-Ruby syntax arguments, like `ls -g pattern`.
|
|
15
|
+
|
|
16
|
+
If you don't know what to pick, go with commands first. Commands are generally safer as they can handle a wider variety of inputs and use cases.
|
|
17
|
+
|
|
18
|
+
## Commands
|
|
19
|
+
|
|
20
|
+
Commands are designed to complete certain tasks or display information for the user, similar to shell commands.
|
|
21
|
+
Therefore, they are designed to accept a variety of inputs, including those that are not valid Ruby code, such
|
|
22
|
+
as `my_cmd Foo#bar` or `my_cmd --flag foo`.
|
|
23
|
+
|
|
24
|
+
### Example
|
|
25
|
+
|
|
26
|
+
```rb
|
|
27
|
+
require "irb/command"
|
|
28
|
+
|
|
29
|
+
class Greet < IRB::Command::Base
|
|
30
|
+
category "Greeting"
|
|
31
|
+
description "Greets the user"
|
|
32
|
+
help_message <<~HELP
|
|
33
|
+
Greets the user with the given name.
|
|
34
|
+
|
|
35
|
+
Usage: greet <name>
|
|
36
|
+
HELP
|
|
37
|
+
|
|
38
|
+
# Any input after the command name will be passed as a single string.
|
|
39
|
+
# If nothing is added after the command, an empty string will be passed.
|
|
40
|
+
def execute(arg)
|
|
41
|
+
puts "Hello! #{arg}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
IRB::Command.register(:greet, Greet)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
As long as the above code is loaded before the IRB session is started, such as in a loaded library or a user's `.irbrc` file, `greet` will be accessible to the user.
|
|
49
|
+
|
|
50
|
+
```txt
|
|
51
|
+
irb(main):001> greet
|
|
52
|
+
Hello!
|
|
53
|
+
=> nil
|
|
54
|
+
irb(main):002> greet Stan
|
|
55
|
+
Hello! Stan
|
|
56
|
+
=> nil
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
And because the `Greet` command introduces a new category, `Greeting`, a new help message category will be created:
|
|
60
|
+
|
|
61
|
+
```txt
|
|
62
|
+
Help
|
|
63
|
+
help List all available commands. Use `help <command>` to get information about a specific command.
|
|
64
|
+
|
|
65
|
+
Greeting
|
|
66
|
+
greet Greets the user
|
|
67
|
+
|
|
68
|
+
IRB
|
|
69
|
+
context Displays current configuration.
|
|
70
|
+
...
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
If the optional `help_message` attribute is specified, `help greet` will also display it:
|
|
74
|
+
|
|
75
|
+
```txt
|
|
76
|
+
irb(main):001> help greet
|
|
77
|
+
Greets the user with the given name.
|
|
78
|
+
|
|
79
|
+
Usage: greet <name>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Helper methods
|
|
83
|
+
|
|
84
|
+
Helper methods are designed to be used as Ruby methods, such as `my_helper(arg, kwarg: val).foo`.
|
|
85
|
+
|
|
86
|
+
The main use case of helper methods is to provide shortcuts for users, providing quick and easy access to
|
|
87
|
+
frequently used operations or components within the IRB session. For example, a helper method might simplify
|
|
88
|
+
the process of fetching and displaying specific configuration settings or data structures that would otherwise
|
|
89
|
+
require multiple steps to access.
|
|
90
|
+
|
|
91
|
+
### Example
|
|
92
|
+
|
|
93
|
+
```rb
|
|
94
|
+
# This only loads the minimum components required to define and register a helper method.
|
|
95
|
+
# It does not load the entire IRB, nor does it initialize it.
|
|
96
|
+
require "irb/helper_method"
|
|
97
|
+
|
|
98
|
+
class MyHelper < IRB::HelperMethod::Base
|
|
99
|
+
description "This is a test helper"
|
|
100
|
+
|
|
101
|
+
def execute(arg, kwarg:)
|
|
102
|
+
"arg: #{arg}, kwarg: #{kwarg}"
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
IRB::HelperMethod.register(:my_helper, MyHelper)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
As long as the above code is loaded before the IRB session is started, such as in a loaded library or a user's `.irbrc` file, `my_helper` will be accessible to the user.
|
|
110
|
+
|
|
111
|
+
```txt
|
|
112
|
+
irb(main):001> my_helper("foo", kwarg: "bar").upcase
|
|
113
|
+
=> "ARG: FOO, KWARG: BAR"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The registered helper methods will also be listed in the help message's `Helper methods` section:
|
|
117
|
+
|
|
118
|
+
```txt
|
|
119
|
+
Helper methods
|
|
120
|
+
conf Returns the current context.
|
|
121
|
+
my_helper This is a test helper
|
|
122
|
+
```
|