irb 1.12.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -11
- data/Rakefile +10 -0
- data/irb.gemspec +1 -1
- data/lib/irb/cmd/nop.rb +1 -1
- data/lib/irb/color.rb +2 -2
- data/lib/irb/command/backtrace.rb +2 -6
- data/lib/irb/command/base.rb +7 -9
- data/lib/irb/command/break.rb +2 -6
- data/lib/irb/command/catch.rb +2 -6
- data/lib/irb/command/chws.rb +11 -5
- data/lib/irb/command/context.rb +16 -0
- data/lib/irb/command/continue.rb +2 -2
- data/lib/irb/command/debug.rb +8 -1
- data/lib/irb/command/delete.rb +2 -2
- data/lib/irb/command/disable_irb.rb +19 -0
- data/lib/irb/command/edit.rb +6 -13
- data/lib/irb/command/exit.rb +1 -3
- data/lib/irb/command/finish.rb +2 -2
- data/lib/irb/command/force_exit.rb +1 -3
- data/lib/irb/command/help.rb +8 -17
- data/lib/irb/command/history.rb +4 -6
- data/lib/irb/command/info.rb +2 -6
- data/lib/irb/command/internal_helpers.rb +27 -0
- data/lib/irb/command/irb_info.rb +2 -2
- data/lib/irb/command/load.rb +20 -3
- data/lib/irb/command/ls.rb +20 -10
- data/lib/irb/command/measure.rb +12 -6
- data/lib/irb/command/next.rb +2 -2
- data/lib/irb/command/pushws.rb +10 -5
- data/lib/irb/command/show_doc.rb +9 -18
- data/lib/irb/command/show_source.rb +5 -12
- data/lib/irb/command/step.rb +2 -2
- data/lib/irb/command/subirb.rb +28 -12
- data/lib/irb/command/whereami.rb +1 -1
- data/lib/irb/command.rb +8 -303
- data/lib/irb/completion.rb +16 -5
- data/lib/irb/context.rb +21 -19
- data/lib/irb/default_commands.rb +260 -0
- data/lib/irb/ext/change-ws.rb +3 -5
- data/lib/irb/ext/multi-irb.rb +4 -4
- data/lib/irb/ext/workspaces.rb +3 -4
- data/lib/irb/help.rb +1 -1
- data/lib/irb/helper_method/base.rb +16 -0
- data/lib/irb/helper_method/conf.rb +11 -0
- data/lib/irb/helper_method.rb +29 -0
- data/lib/irb/history.rb +6 -3
- data/lib/irb/init.rb +60 -44
- data/lib/irb/input-method.rb +18 -10
- data/lib/irb/lc/error.rb +0 -5
- data/lib/irb/lc/ja/error.rb +0 -5
- data/lib/irb/lc/ja/help-message +10 -0
- data/lib/irb/statement.rb +5 -27
- data/lib/irb/version.rb +2 -2
- data/lib/irb/workspace.rb +18 -2
- data/lib/irb.rb +675 -624
- metadata +12 -5
data/lib/irb.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
# :markup: markdown
|
3
4
|
# irb.rb - irb main module
|
4
5
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
6
|
#
|
@@ -9,7 +10,7 @@ require "reline"
|
|
9
10
|
|
10
11
|
require_relative "irb/init"
|
11
12
|
require_relative "irb/context"
|
12
|
-
require_relative "irb/
|
13
|
+
require_relative "irb/default_commands"
|
13
14
|
|
14
15
|
require_relative "irb/ruby-lex"
|
15
16
|
require_relative "irb/statement"
|
@@ -22,545 +23,550 @@ require_relative "irb/easter-egg"
|
|
22
23
|
require_relative "irb/debug"
|
23
24
|
require_relative "irb/pager"
|
24
25
|
|
25
|
-
#
|
26
|
+
# ## IRB
|
26
27
|
#
|
27
|
-
#
|
28
|
-
#
|
28
|
+
# Module IRB ("Interactive Ruby") provides a shell-like interface that supports
|
29
|
+
# user interaction with the Ruby interpreter.
|
29
30
|
#
|
30
|
-
# It operates as a
|
31
|
-
# (
|
31
|
+
# It operates as a *read-eval-print loop*
|
32
|
+
# ([REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop))
|
32
33
|
# that:
|
33
34
|
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
35
|
+
# * ***Reads*** each character as you type. You can modify the IRB context to
|
36
|
+
# change the way input works. See [Input](rdoc-ref:IRB@Input).
|
37
|
+
# * ***Evaluates*** the code each time it has read a syntactically complete
|
38
|
+
# passage.
|
39
|
+
# * ***Prints*** after evaluating. You can modify the IRB context to change
|
40
|
+
# the way output works. See [Output](rdoc-ref:IRB@Output).
|
41
|
+
#
|
41
42
|
#
|
42
43
|
# Example:
|
43
44
|
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
45
|
+
# $ irb
|
46
|
+
# irb(main):001> File.basename(Dir.pwd)
|
47
|
+
# => "irb"
|
48
|
+
# irb(main):002> Dir.entries('.').size
|
49
|
+
# => 25
|
50
|
+
# irb(main):003* Dir.entries('.').select do |entry|
|
51
|
+
# irb(main):004* entry.start_with?('R')
|
52
|
+
# irb(main):005> end
|
53
|
+
# => ["README.md", "Rakefile"]
|
54
|
+
#
|
55
|
+
# The typed input may also include [\IRB-specific
|
56
|
+
# commands](rdoc-ref:IRB@IRB-Specific+Commands).
|
53
57
|
#
|
54
|
-
#
|
55
|
-
# {\IRB-specific commands}[rdoc-ref:IRB@IRB-Specific+Commands].
|
58
|
+
# As seen above, you can start IRB by using the shell command `irb`.
|
56
59
|
#
|
57
|
-
#
|
60
|
+
# You can stop an IRB session by typing command `exit`:
|
58
61
|
#
|
59
|
-
#
|
62
|
+
# irb(main):006> exit
|
63
|
+
# $
|
60
64
|
#
|
61
|
-
#
|
62
|
-
#
|
65
|
+
# At that point, IRB calls any hooks found in array `IRB.conf[:AT_EXIT]`, then
|
66
|
+
# exits.
|
63
67
|
#
|
64
|
-
#
|
65
|
-
# then exits.
|
68
|
+
# ## Startup
|
66
69
|
#
|
67
|
-
#
|
70
|
+
# At startup, IRB:
|
68
71
|
#
|
69
|
-
#
|
72
|
+
# 1. Interprets (as Ruby code) the content of the [configuration
|
73
|
+
# file](rdoc-ref:IRB@Configuration+File) (if given).
|
74
|
+
# 2. Constructs the initial session context from [hash
|
75
|
+
# IRB.conf](rdoc-ref:IRB@Hash+IRB.conf) and from default values; the hash
|
76
|
+
# content may have been affected by [command-line
|
77
|
+
# options](rdoc-ref:IB@Command-Line+Options), and by direct assignments in
|
78
|
+
# the configuration file.
|
79
|
+
# 3. Assigns the context to variable `conf`.
|
80
|
+
# 4. Assigns command-line arguments to variable `ARGV`.
|
81
|
+
# 5. Prints the [prompt](rdoc-ref:IRB@Prompt+and+Return+Formats).
|
82
|
+
# 6. Puts the content of the [initialization
|
83
|
+
# script](rdoc-ref:IRB@Initialization+Script) onto the IRB shell, just as if
|
84
|
+
# it were user-typed commands.
|
70
85
|
#
|
71
|
-
# 1. Interprets (as Ruby code) the content of the
|
72
|
-
# {configuration file}[rdoc-ref:IRB@Configuration+File] (if given).
|
73
|
-
# 1. Constructs the initial session context
|
74
|
-
# from {hash IRB.conf}[rdoc-ref:IRB@Hash+IRB.conf] and from default values;
|
75
|
-
# the hash content may have been affected
|
76
|
-
# by {command-line options}[rdoc-ref:IB@Command-Line+Options],
|
77
|
-
# and by direct assignments in the configuration file.
|
78
|
-
# 1. Assigns the context to variable +conf+.
|
79
|
-
# 1. Assigns command-line arguments to variable <tt>ARGV</tt>.
|
80
|
-
# 1. Prints the {prompt}[rdoc-ref:IRB@Prompt+and+Return+Formats].
|
81
|
-
# 1. Puts the content of the
|
82
|
-
# {initialization script}[rdoc-ref:IRB@Initialization+Script]
|
83
|
-
# onto the \IRB shell, just as if it were user-typed commands.
|
84
86
|
#
|
85
|
-
#
|
87
|
+
# ### The Command Line
|
86
88
|
#
|
87
|
-
# On the command line, all options precede all arguments;
|
88
|
-
#
|
89
|
-
#
|
89
|
+
# On the command line, all options precede all arguments; the first item that is
|
90
|
+
# not recognized as an option is treated as an argument, as are all items that
|
91
|
+
# follow.
|
90
92
|
#
|
91
|
-
#
|
93
|
+
# #### Command-Line Options
|
92
94
|
#
|
93
|
-
# Many command-line options affect entries in hash
|
94
|
-
#
|
95
|
+
# Many command-line options affect entries in hash `IRB.conf`, which in turn
|
96
|
+
# affect the initial configuration of the IRB session.
|
95
97
|
#
|
96
98
|
# Details of the options are described in the relevant subsections below.
|
97
99
|
#
|
98
|
-
# A cursory list of the
|
99
|
-
#
|
100
|
-
# which is also displayed if you use command-line option
|
100
|
+
# A cursory list of the IRB command-line options may be seen in the [help
|
101
|
+
# message](https://raw.githubusercontent.com/ruby/irb/master/lib/irb/lc/help-message),
|
102
|
+
# which is also displayed if you use command-line option `--help`.
|
101
103
|
#
|
102
104
|
# If you are interested in a specific option, consult the
|
103
|
-
#
|
105
|
+
# [index](rdoc-ref:doc/irb/indexes.md@Index+of+Command-Line+Options).
|
104
106
|
#
|
105
|
-
#
|
107
|
+
# #### Command-Line Arguments
|
106
108
|
#
|
107
|
-
# Command-line arguments are passed to
|
109
|
+
# Command-line arguments are passed to IRB in array `ARGV`:
|
108
110
|
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
111
|
+
# $ irb --noscript Foo Bar Baz
|
112
|
+
# irb(main):001> ARGV
|
113
|
+
# => ["Foo", "Bar", "Baz"]
|
114
|
+
# irb(main):002> exit
|
115
|
+
# $
|
114
116
|
#
|
115
|
-
# Command-line option
|
116
|
-
#
|
117
|
+
# Command-line option `--` causes everything that follows to be treated as
|
118
|
+
# arguments, even those that look like options:
|
117
119
|
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
120
|
+
# $ irb --noscript -- --noscript -- Foo Bar Baz
|
121
|
+
# irb(main):001> ARGV
|
122
|
+
# => ["--noscript", "--", "Foo", "Bar", "Baz"]
|
123
|
+
# irb(main):002> exit
|
124
|
+
# $
|
123
125
|
#
|
124
|
-
#
|
126
|
+
# ### Configuration File
|
125
127
|
#
|
126
|
-
# You can initialize
|
128
|
+
# You can initialize IRB via a *configuration file*.
|
127
129
|
#
|
128
|
-
# If command-line option
|
129
|
-
# no configuration file is looked for.
|
130
|
+
# If command-line option `-f` is given, no configuration file is looked for.
|
130
131
|
#
|
131
|
-
# Otherwise,
|
132
|
-
# if one is available.
|
132
|
+
# Otherwise, IRB reads and interprets a configuration file if one is available.
|
133
133
|
#
|
134
134
|
# The configuration file can contain any Ruby code, and can usefully include
|
135
135
|
# user code that:
|
136
136
|
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
137
|
+
# * Can then be debugged in IRB.
|
138
|
+
# * Configures IRB itself.
|
139
|
+
# * Requires or loads files.
|
140
|
+
#
|
140
141
|
#
|
141
142
|
# The path to the configuration file is the first found among:
|
142
143
|
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
144
|
+
# * The value of variable `$IRBRC`, if defined.
|
145
|
+
# * The value of variable `$XDG_CONFIG_HOME/irb/irbrc`, if defined.
|
146
|
+
# * File `$HOME/.irbrc`, if it exists.
|
147
|
+
# * File `$HOME/.config/irb/irbrc`, if it exists.
|
148
|
+
# * File `.irbrc` in the current directory, if it exists.
|
149
|
+
# * File `irb.rc` in the current directory, if it exists.
|
150
|
+
# * File `_irbrc` in the current directory, if it exists.
|
151
|
+
# * File `$irbrc` in the current directory, if it exists.
|
152
|
+
#
|
152
153
|
#
|
153
154
|
# If the search fails, there is no configuration file.
|
154
155
|
#
|
155
|
-
# If the search succeeds, the configuration file is read as Ruby code,
|
156
|
-
#
|
156
|
+
# If the search succeeds, the configuration file is read as Ruby code, and so
|
157
|
+
# can contain any Ruby programming you like.
|
158
|
+
#
|
159
|
+
# Method `conf.rc?` returns `true` if a configuration file was read, `false`
|
160
|
+
# otherwise. Hash entry `IRB.conf[:RC]` also contains that value.
|
157
161
|
#
|
158
|
-
#
|
159
|
-
# +false+ otherwise.
|
160
|
-
# \Hash entry <tt>IRB.conf[:RC]</tt> also contains that value.
|
162
|
+
# ### Hash `IRB.conf`
|
161
163
|
#
|
162
|
-
#
|
164
|
+
# The initial entries in hash `IRB.conf` are determined by:
|
163
165
|
#
|
164
|
-
#
|
166
|
+
# * Default values.
|
167
|
+
# * Command-line options, which may override defaults.
|
168
|
+
# * Direct assignments in the configuration file.
|
165
169
|
#
|
166
|
-
# - Default values.
|
167
|
-
# - Command-line options, which may override defaults.
|
168
|
-
# - Direct assignments in the configuration file.
|
169
170
|
#
|
170
|
-
# You can see the hash by typing
|
171
|
+
# You can see the hash by typing `IRB.conf`.
|
171
172
|
#
|
172
|
-
# Details of the entries' meanings are described in the relevant subsections
|
173
|
+
# Details of the entries' meanings are described in the relevant subsections
|
174
|
+
# below.
|
173
175
|
#
|
174
176
|
# If you are interested in a specific entry, consult the
|
175
|
-
#
|
177
|
+
# [index](rdoc-ref:doc/irb/indexes.md@Index+of+IRB.conf+Entries).
|
178
|
+
#
|
179
|
+
# ### Notes on Initialization Precedence
|
176
180
|
#
|
177
|
-
#
|
181
|
+
# * Any conflict between an entry in hash `IRB.conf` and a command-line option
|
182
|
+
# is resolved in favor of the hash entry.
|
183
|
+
# * Hash `IRB.conf` affects the context only once, when the configuration file
|
184
|
+
# is interpreted; any subsequent changes to it do not affect the context and
|
185
|
+
# are therefore essentially meaningless.
|
178
186
|
#
|
179
|
-
# - Any conflict between an entry in hash <tt>IRB.conf</tt> and a command-line option
|
180
|
-
# is resolved in favor of the hash entry.
|
181
|
-
# - \Hash <tt>IRB.conf</tt> affects the context only once,
|
182
|
-
# when the configuration file is interpreted;
|
183
|
-
# any subsequent changes to it do not affect the context
|
184
|
-
# and are therefore essentially meaningless.
|
185
187
|
#
|
186
|
-
#
|
188
|
+
# ### Initialization Script
|
187
189
|
#
|
188
|
-
# By default, the first command-line argument (after any options)
|
189
|
-
#
|
190
|
+
# By default, the first command-line argument (after any options) is the path to
|
191
|
+
# a Ruby initialization script.
|
190
192
|
#
|
191
|
-
#
|
193
|
+
# IRB reads the initialization script and puts its content onto the IRB shell,
|
192
194
|
# just as if it were user-typed commands.
|
193
195
|
#
|
194
|
-
# Command-line option
|
195
|
-
#
|
196
|
-
#
|
196
|
+
# Command-line option `--noscript` causes the first command-line argument to be
|
197
|
+
# treated as an ordinary argument (instead of an initialization script);
|
198
|
+
# `--script` is the default.
|
197
199
|
#
|
198
|
-
#
|
200
|
+
# ## Input
|
199
201
|
#
|
200
|
-
# This section describes the features that allow you to change
|
201
|
-
#
|
202
|
-
# see also {Input and Output}[rdoc-ref:IRB@Input+and+Output].
|
202
|
+
# This section describes the features that allow you to change the way IRB input
|
203
|
+
# works; see also [Input and Output](rdoc-ref:IRB@Input+and+Output).
|
203
204
|
#
|
204
|
-
#
|
205
|
+
# ### Input Command History
|
205
206
|
#
|
206
|
-
# By default,
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
207
|
+
# By default, IRB stores a history of up to 1000 input commands in a file named
|
208
|
+
# `.irb_history`. The history file will be in the same directory as the
|
209
|
+
# [configuration file](rdoc-ref:IRB@Configuration+File) if one is found, or in
|
210
|
+
# `~/` otherwise.
|
210
211
|
#
|
211
|
-
# A new
|
212
|
-
#
|
212
|
+
# A new IRB session creates the history file if it does not exist, and appends
|
213
|
+
# to the file if it does exist.
|
213
214
|
#
|
214
215
|
# You can change the filepath by adding to your configuration file:
|
215
|
-
#
|
216
|
-
# where _filepath_ is a string filepath.
|
216
|
+
# `IRB.conf[:HISTORY_FILE] = *filepath*`, where *filepath* is a string filepath.
|
217
217
|
#
|
218
|
-
# During the session, method
|
219
|
-
#
|
220
|
-
#
|
221
|
-
# which becomes the history file for the session.
|
218
|
+
# During the session, method `conf.history_file` returns the filepath, and
|
219
|
+
# method `conf.history_file = *new_filepath*` copies the history to the file at
|
220
|
+
# *new_filepath*, which becomes the history file for the session.
|
222
221
|
#
|
223
|
-
# You can change the number of commands saved by adding to your configuration
|
224
|
-
#
|
225
|
-
# where _n_ is one of:
|
222
|
+
# You can change the number of commands saved by adding to your configuration
|
223
|
+
# file: `IRB.conf[:SAVE_HISTORY] = *n*`, wheHISTORY_FILEre *n* is one of:
|
226
224
|
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
225
|
+
# * Positive integer: the number of commands to be saved,
|
226
|
+
# * Zero: all commands are to be saved.
|
227
|
+
# * `nil`: no commands are to be saved,.
|
230
228
|
#
|
231
|
-
# During the session, you can use
|
232
|
-
# methods <tt>conf.save_history</tt> or <tt>conf.save_history=</tt>
|
233
|
-
# to retrieve or change the count.
|
234
229
|
#
|
235
|
-
#
|
230
|
+
# During the session, you can use methods `conf.save_history` or
|
231
|
+
# `conf.save_history=` to retrieve or change the count.
|
236
232
|
#
|
237
|
-
#
|
233
|
+
# ### Command Aliases
|
238
234
|
#
|
239
|
-
#
|
240
|
-
#
|
235
|
+
# By default, IRB defines several command aliases:
|
236
|
+
#
|
237
|
+
# irb(main):001> conf.command_aliases
|
238
|
+
# => {:"$"=>:show_source, :"@"=>:whereami}
|
241
239
|
#
|
242
240
|
# You can change the initial aliases in the configuration file with:
|
243
241
|
#
|
244
|
-
#
|
242
|
+
# IRB.conf[:COMMAND_ALIASES] = {foo: :show_source, bar: :whereami}
|
245
243
|
#
|
246
|
-
# You can replace the current aliases at any time
|
247
|
-
#
|
248
|
-
#
|
249
|
-
# you can modify it.
|
244
|
+
# You can replace the current aliases at any time with configuration method
|
245
|
+
# `conf.command_aliases=`; Because `conf.command_aliases` is a hash, you can
|
246
|
+
# modify it.
|
250
247
|
#
|
251
|
-
#
|
248
|
+
# ### End-of-File
|
252
249
|
#
|
253
|
-
# By default,
|
254
|
-
#
|
255
|
-
# causes the session to exit.
|
250
|
+
# By default, `IRB.conf[:IGNORE_EOF]` is `false`, which means that typing the
|
251
|
+
# end-of-file character `Ctrl-D` causes the session to exit.
|
256
252
|
#
|
257
|
-
# You can reverse that behavior by adding
|
258
|
-
#
|
253
|
+
# You can reverse that behavior by adding `IRB.conf[:IGNORE_EOF] = true` to the
|
254
|
+
# configuration file.
|
259
255
|
#
|
260
|
-
# During the session, method
|
261
|
-
#
|
256
|
+
# During the session, method `conf.ignore_eof?` returns the setting, and method
|
257
|
+
# `conf.ignore_eof = *boolean*` sets it.
|
262
258
|
#
|
263
|
-
#
|
259
|
+
# ### SIGINT
|
264
260
|
#
|
265
|
-
# By default,
|
266
|
-
#
|
267
|
-
# causes the session to exit.
|
261
|
+
# By default, `IRB.conf[:IGNORE_SIGINT]` is `true`, which means that typing the
|
262
|
+
# interrupt character `Ctrl-C` causes the session to exit.
|
268
263
|
#
|
269
|
-
# You can reverse that behavior by adding
|
270
|
-
#
|
264
|
+
# You can reverse that behavior by adding `IRB.conf[:IGNORE_SIGING] = false` to
|
265
|
+
# the configuration file.
|
271
266
|
#
|
272
|
-
# During the session, method
|
273
|
-
#
|
267
|
+
# During the session, method `conf.ignore_siging?` returns the setting, and
|
268
|
+
# method `conf.ignore_sigint = *boolean*` sets it.
|
274
269
|
#
|
275
|
-
#
|
270
|
+
# ### Automatic Completion
|
276
271
|
#
|
277
|
-
# By default,
|
278
|
-
#
|
272
|
+
# By default, IRB enables [automatic
|
273
|
+
# completion](https://en.wikipedia.org/wiki/Autocomplete#In_command-line_interpr
|
274
|
+
# eters):
|
279
275
|
#
|
280
276
|
# You can disable it by either of these:
|
281
277
|
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
278
|
+
# * Adding `IRB.conf[:USE_AUTOCOMPLETE] = false` to the configuration file.
|
279
|
+
# * Giving command-line option `--noautocomplete` (`--autocomplete` is the
|
280
|
+
# default).
|
281
|
+
#
|
285
282
|
#
|
286
|
-
#
|
287
|
-
#
|
283
|
+
# Method `conf.use_autocomplete?` returns `true` if automatic completion is
|
284
|
+
# enabled, `false` otherwise.
|
288
285
|
#
|
289
286
|
# The setting may not be changed during the session.
|
290
287
|
#
|
291
|
-
#
|
288
|
+
# ### Automatic Indentation
|
292
289
|
#
|
293
|
-
# By default,
|
294
|
-
#
|
290
|
+
# By default, IRB automatically indents lines of code to show structure (e.g.,
|
291
|
+
# it indent the contents of a block).
|
295
292
|
#
|
296
|
-
# The current setting is returned
|
297
|
-
#
|
293
|
+
# The current setting is returned by the configuration method
|
294
|
+
# `conf.auto_indent_mode`.
|
298
295
|
#
|
299
|
-
# The default initial setting is
|
296
|
+
# The default initial setting is `true`:
|
300
297
|
#
|
301
|
-
#
|
302
|
-
#
|
303
|
-
#
|
304
|
-
#
|
305
|
-
#
|
306
|
-
#
|
298
|
+
# irb(main):001> conf.auto_indent_mode
|
299
|
+
# => true
|
300
|
+
# irb(main):002* Dir.entries('.').select do |entry|
|
301
|
+
# irb(main):003* entry.start_with?('R')
|
302
|
+
# irb(main):004> end
|
303
|
+
# => ["README.md", "Rakefile"]
|
307
304
|
#
|
308
|
-
# You can change the initial setting in the
|
309
|
-
# configuration file with:
|
305
|
+
# You can change the initial setting in the configuration file with:
|
310
306
|
#
|
311
|
-
#
|
307
|
+
# IRB.conf[:AUTO_INDENT] = false
|
312
308
|
#
|
313
|
-
# Note that the
|
309
|
+
# Note that the *current* setting *may not* be changed in the IRB session.
|
314
310
|
#
|
315
|
-
#
|
311
|
+
# ### Input Method
|
316
312
|
#
|
317
|
-
# The
|
318
|
-
#
|
313
|
+
# The IRB input method determines how command input is to be read; by default,
|
314
|
+
# the input method for a session is IRB::RelineInputMethod.
|
319
315
|
#
|
320
316
|
# You can set the input method by:
|
321
317
|
#
|
322
|
-
#
|
318
|
+
# * Adding to the configuration file:
|
319
|
+
#
|
320
|
+
# * `IRB.conf[:USE_SINGLELINE] = true` or `IRB.conf[:USE_MULTILINE]=
|
321
|
+
# false` sets the input method to IRB::ReadlineInputMethod.
|
322
|
+
# * `IRB.conf[:USE_SINGLELINE] = false` or `IRB.conf[:USE_MULTILINE] =
|
323
|
+
# true` sets the input method to IRB::RelineInputMethod.
|
324
|
+
#
|
325
|
+
#
|
326
|
+
# * Giving command-line options:
|
327
|
+
#
|
328
|
+
# * `--singleline` or `--nomultiline` sets the input method to
|
329
|
+
# IRB::ReadlineInputMethod.
|
330
|
+
# * `--nosingleline` or `--multiline` sets the input method to
|
331
|
+
# IRB::RelineInputMethod.
|
323
332
|
#
|
324
|
-
# - <tt>IRB.conf[:USE_SINGLELINE] = true</tt>
|
325
|
-
# or <tt>IRB.conf[:USE_MULTILINE]= false</tt>
|
326
|
-
# sets the input method to IRB::ReadlineInputMethod.
|
327
|
-
# - <tt>IRB.conf[:USE_SINGLELINE] = false</tt>
|
328
|
-
# or <tt>IRB.conf[:USE_MULTILINE] = true</tt>
|
329
|
-
# sets the input method to IRB::RelineInputMethod.
|
330
333
|
#
|
331
|
-
# - Giving command-line options:
|
332
334
|
#
|
333
|
-
#
|
334
|
-
# or <tt>--nomultiline</tt>
|
335
|
-
# sets the input method to IRB::ReadlineInputMethod.
|
336
|
-
# - <tt>--nosingleline</tt>
|
337
|
-
# or <tt>--multiline/tt>
|
338
|
-
# sets the input method to IRB::RelineInputMethod.
|
335
|
+
# Method `conf.use_multiline?` and its synonym `conf.use_reline` return:
|
339
336
|
#
|
340
|
-
#
|
341
|
-
#
|
337
|
+
# * `true` if option `--multiline` was given.
|
338
|
+
# * `false` if option `--nomultiline` was given.
|
339
|
+
# * `nil` if neither was given.
|
342
340
|
#
|
343
|
-
# - +true+ if option <tt>--multiline</tt> was given.
|
344
|
-
# - +false+ if option <tt>--nomultiline</tt> was given.
|
345
|
-
# - +nil+ if neither was given.
|
346
341
|
#
|
347
|
-
#
|
348
|
-
# and its synonym <tt>conf.use_readline</tt> return:
|
342
|
+
# Method `conf.use_singleline?` and its synonym `conf.use_readline` return:
|
349
343
|
#
|
350
|
-
#
|
351
|
-
#
|
352
|
-
#
|
344
|
+
# * `true` if option `--singleline` was given.
|
345
|
+
# * `false` if option `--nosingleline` was given.
|
346
|
+
# * `nil` if neither was given.
|
353
347
|
#
|
354
|
-
# == Output
|
355
348
|
#
|
356
|
-
#
|
357
|
-
# the way \IRB output works;
|
358
|
-
# see also {Input and Output}[rdoc-ref:IRB@Input+and+Output].
|
349
|
+
# ## Output
|
359
350
|
#
|
360
|
-
#
|
351
|
+
# This section describes the features that allow you to change the way IRB
|
352
|
+
# output works; see also [Input and Output](rdoc-ref:IRB@Input+and+Output).
|
361
353
|
#
|
362
|
-
#
|
354
|
+
# ### Return-Value Printing (Echoing)
|
355
|
+
#
|
356
|
+
# By default, IRB prints (echoes) the values returned by all input commands.
|
363
357
|
#
|
364
358
|
# You can change the initial behavior and suppress all echoing by:
|
365
359
|
#
|
366
|
-
#
|
367
|
-
#
|
368
|
-
#
|
369
|
-
#
|
360
|
+
# * Adding to the configuration file: `IRB.conf[:ECHO] = false`. (The default
|
361
|
+
# value for this entry is `nil`, which means the same as `true`.)
|
362
|
+
# * Giving command-line option `--noecho`. (The default is `--echo`.)
|
363
|
+
#
|
364
|
+
#
|
365
|
+
# During the session, you can change the current setting with configuration
|
366
|
+
# method `conf.echo=` (set to `true` or `false`).
|
367
|
+
#
|
368
|
+
# As stated above, by default IRB prints the values returned by all input
|
369
|
+
# commands; but IRB offers special treatment for values returned by assignment
|
370
|
+
# statements, which may be:
|
371
|
+
#
|
372
|
+
# * Printed with truncation (to fit on a single line of output), which is the
|
373
|
+
# default; an ellipsis (`...` is suffixed, to indicate the truncation):
|
370
374
|
#
|
371
|
-
#
|
372
|
-
# with configuration method <tt>conf.echo=</tt> (set to +true+ or +false+).
|
375
|
+
# irb(main):001> x = 'abc' * 100
|
373
376
|
#
|
374
|
-
# As stated above, by default \IRB prints the values returned by all input commands;
|
375
|
-
# but \IRB offers special treatment for values returned by assignment statements,
|
376
|
-
# which may be:
|
377
377
|
#
|
378
|
-
#
|
379
|
-
# which is the default;
|
380
|
-
# an ellipsis (<tt>...</tt> is suffixed, to indicate the truncation):
|
378
|
+
# > "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc...
|
381
379
|
#
|
382
|
-
#
|
383
|
-
#
|
380
|
+
# * Printed in full (regardless of the length).
|
381
|
+
# * Suppressed (not printed at all)
|
384
382
|
#
|
385
|
-
# - Printed in full (regardless of the length).
|
386
|
-
# - Suppressed (not printed at all)
|
387
383
|
#
|
388
384
|
# You can change the initial behavior by:
|
389
385
|
#
|
390
|
-
#
|
391
|
-
#
|
392
|
-
#
|
393
|
-
#
|
394
|
-
#
|
386
|
+
# * Adding to the configuration file: `IRB.conf[:ECHO_ON_ASSIGNMENT] = false`.
|
387
|
+
# (The default value for this entry is `niL`, which means the same as
|
388
|
+
# `:truncate`.)
|
389
|
+
# * Giving command-line option `--noecho-on-assignment` or
|
390
|
+
# `--echo-on-assignment`. (The default is `--truncate-echo-on-assignment`.)
|
395
391
|
#
|
396
|
-
# During the session, you can change the current setting
|
397
|
-
# with configuration method <tt>conf.echo_on_assignment=</tt>
|
398
|
-
# (set to +true+, +false+, or +:truncate+).
|
399
392
|
#
|
400
|
-
#
|
393
|
+
# During the session, you can change the current setting with configuration
|
394
|
+
# method `conf.echo_on_assignment=` (set to `true`, `false`, or `:truncate`).
|
395
|
+
#
|
396
|
+
# By default, IRB formats returned values by calling method `inspect`.
|
401
397
|
#
|
402
398
|
# You can change the initial behavior by:
|
403
399
|
#
|
404
|
-
#
|
405
|
-
#
|
406
|
-
#
|
407
|
-
#
|
400
|
+
# * Adding to the configuration file: `IRB.conf[:INSPECT_MODE] = false`. (The
|
401
|
+
# default value for this entry is `true`.)
|
402
|
+
# * Giving command-line option `--noinspect`. (The default is `--inspect`.)
|
403
|
+
#
|
408
404
|
#
|
409
|
-
# During the session, you can change the setting using method
|
405
|
+
# During the session, you can change the setting using method
|
406
|
+
# `conf.inspect_mode=`.
|
410
407
|
#
|
411
|
-
#
|
408
|
+
# ### Multiline Output
|
412
409
|
#
|
413
|
-
# By default,
|
410
|
+
# By default, IRB prefixes a newline to a multiline response.
|
414
411
|
#
|
415
412
|
# You can change the initial default value by adding to the configuration file:
|
416
413
|
#
|
417
|
-
#
|
414
|
+
# IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT] = false
|
418
415
|
#
|
419
|
-
# During a session, you can retrieve or set the value using
|
420
|
-
#
|
421
|
-
#
|
416
|
+
# During a session, you can retrieve or set the value using methods
|
417
|
+
# `conf.newline_before_multiline_output?` and
|
418
|
+
# `conf.newline_before_multiline_output=`.
|
422
419
|
#
|
423
420
|
# Examples:
|
424
421
|
#
|
425
|
-
#
|
426
|
-
#
|
427
|
-
#
|
428
|
-
#
|
429
|
-
#
|
430
|
-
#
|
431
|
-
#
|
432
|
-
#
|
433
|
-
#
|
434
|
-
#
|
435
|
-
#
|
422
|
+
# irb(main):001> conf.inspect_mode = false
|
423
|
+
# => false
|
424
|
+
# irb(main):002> "foo\nbar"
|
425
|
+
# =>
|
426
|
+
# foo
|
427
|
+
# bar
|
428
|
+
# irb(main):003> conf.newline_before_multiline_output = false
|
429
|
+
# => false
|
430
|
+
# irb(main):004> "foo\nbar"
|
431
|
+
# => foo
|
432
|
+
# bar
|
433
|
+
#
|
434
|
+
# ### Evaluation History
|
436
435
|
#
|
437
|
-
#
|
436
|
+
# By default, IRB saves no history of evaluations (returned values), and the
|
437
|
+
# related methods `conf.eval_history`, `_`, and `__` are undefined.
|
438
438
|
#
|
439
|
-
#
|
440
|
-
#
|
441
|
-
# and <tt>__</tt> are undefined.
|
439
|
+
# You can turn on that history, and set the maximum number of evaluations to be
|
440
|
+
# stored:
|
442
441
|
#
|
443
|
-
#
|
442
|
+
# * In the configuration file: add `IRB.conf[:EVAL_HISTORY] = *n*`. (Examples
|
443
|
+
# below assume that we've added `IRB.conf[:EVAL_HISTORY] = 5`.)
|
444
|
+
# * In the session (at any time): `conf.eval_history = *n*`.
|
444
445
|
#
|
445
|
-
# - In the configuration file: add <tt>IRB.conf[:EVAL_HISTORY] = _n_</tt>.
|
446
|
-
# (Examples below assume that we've added <tt>IRB.conf[:EVAL_HISTORY] = 5</tt>.)
|
447
|
-
# - In the session (at any time): <tt>conf.eval_history = _n_</tt>.
|
448
446
|
#
|
449
|
-
# If
|
447
|
+
# If `n` is zero, all evaluation history is stored.
|
450
448
|
#
|
451
449
|
# Doing either of the above:
|
452
450
|
#
|
453
|
-
#
|
454
|
-
#
|
455
|
-
#
|
456
|
-
#
|
457
|
-
#
|
458
|
-
#
|
459
|
-
#
|
460
|
-
#
|
461
|
-
#
|
462
|
-
#
|
463
|
-
#
|
464
|
-
#
|
465
|
-
#
|
466
|
-
#
|
467
|
-
#
|
468
|
-
#
|
469
|
-
#
|
470
|
-
#
|
471
|
-
#
|
472
|
-
#
|
473
|
-
#
|
474
|
-
#
|
475
|
-
#
|
476
|
-
#
|
477
|
-
#
|
478
|
-
#
|
479
|
-
#
|
480
|
-
#
|
481
|
-
#
|
482
|
-
#
|
483
|
-
#
|
484
|
-
#
|
485
|
-
#
|
486
|
-
#
|
487
|
-
#
|
488
|
-
#
|
489
|
-
#
|
490
|
-
#
|
491
|
-
#
|
492
|
-
#
|
493
|
-
#
|
494
|
-
#
|
495
|
-
#
|
496
|
-
#
|
497
|
-
#
|
498
|
-
#
|
499
|
-
#
|
500
|
-
#
|
501
|
-
#
|
502
|
-
#
|
503
|
-
#
|
504
|
-
#
|
505
|
-
#
|
506
|
-
#
|
507
|
-
#
|
508
|
-
#
|
509
|
-
#
|
510
|
-
#
|
511
|
-
#
|
512
|
-
#
|
513
|
-
#
|
514
|
-
#
|
515
|
-
#
|
516
|
-
#
|
517
|
-
#
|
518
|
-
#
|
519
|
-
#
|
520
|
-
#
|
521
|
-
#
|
522
|
-
#
|
523
|
-
#
|
524
|
-
#
|
525
|
-
#
|
526
|
-
#
|
527
|
-
#
|
528
|
-
#
|
529
|
-
#
|
530
|
-
#
|
531
|
-
#
|
532
|
-
#
|
533
|
-
#
|
451
|
+
# * Sets the maximum size of the evaluation history; defines method
|
452
|
+
# `conf.eval_history`, which returns the maximum size `n` of the evaluation
|
453
|
+
# history:
|
454
|
+
#
|
455
|
+
# irb(main):001> conf.eval_history = 5
|
456
|
+
# => 5
|
457
|
+
# irb(main):002> conf.eval_history
|
458
|
+
# => 5
|
459
|
+
#
|
460
|
+
# * Defines variable `_`, which contains the most recent evaluation, or `nil`
|
461
|
+
# if none; same as method `conf.last_value`:
|
462
|
+
#
|
463
|
+
# irb(main):003> _
|
464
|
+
# => 5
|
465
|
+
# irb(main):004> :foo
|
466
|
+
# => :foo
|
467
|
+
# irb(main):005> :bar
|
468
|
+
# => :bar
|
469
|
+
# irb(main):006> _
|
470
|
+
# => :bar
|
471
|
+
# irb(main):007> _
|
472
|
+
# => :bar
|
473
|
+
#
|
474
|
+
# * Defines variable `__`:
|
475
|
+
#
|
476
|
+
# * `__` unadorned: contains all evaluation history:
|
477
|
+
#
|
478
|
+
# irb(main):008> :foo
|
479
|
+
# => :foo
|
480
|
+
# irb(main):009> :bar
|
481
|
+
# => :bar
|
482
|
+
# irb(main):010> :baz
|
483
|
+
# => :baz
|
484
|
+
# irb(main):011> :bat
|
485
|
+
# => :bat
|
486
|
+
# irb(main):012> :bam
|
487
|
+
# => :bam
|
488
|
+
# irb(main):013> __
|
489
|
+
# =>
|
490
|
+
# 9 :bar
|
491
|
+
# 10 :baz
|
492
|
+
# 11 :bat
|
493
|
+
# 12 :bam
|
494
|
+
# irb(main):014> __
|
495
|
+
# =>
|
496
|
+
# 10 :baz
|
497
|
+
# 11 :bat
|
498
|
+
# 12 :bam
|
499
|
+
# 13 ...self-history...
|
500
|
+
#
|
501
|
+
# Note that when the evaluation is multiline, it is displayed
|
502
|
+
# differently.
|
503
|
+
#
|
504
|
+
# * `__[`*m*`]`:
|
505
|
+
#
|
506
|
+
# * Positive *m*: contains the evaluation for the given line number,
|
507
|
+
# or `nil` if that line number is not in the evaluation history:
|
508
|
+
#
|
509
|
+
# irb(main):015> __[12]
|
510
|
+
# => :bam
|
511
|
+
# irb(main):016> __[1]
|
512
|
+
# => nil
|
513
|
+
#
|
514
|
+
# * Negative *m*: contains the `mth`-from-end evaluation, or `nil` if
|
515
|
+
# that evaluation is not in the evaluation history:
|
516
|
+
#
|
517
|
+
# irb(main):017> __[-3]
|
518
|
+
# => :bam
|
519
|
+
# irb(main):018> __[-13]
|
520
|
+
# => nil
|
521
|
+
#
|
522
|
+
# * Zero *m*: contains `nil`:
|
523
|
+
#
|
524
|
+
# irb(main):019> __[0]
|
525
|
+
# => nil
|
526
|
+
#
|
527
|
+
#
|
528
|
+
#
|
529
|
+
#
|
530
|
+
# ### Prompt and Return Formats
|
531
|
+
#
|
532
|
+
# By default, IRB uses the prompt and return value formats defined in its
|
533
|
+
# `:DEFAULT` prompt mode.
|
534
|
+
#
|
535
|
+
# #### The Default Prompt and Return Format
|
534
536
|
#
|
535
537
|
# The default prompt and return values look like this:
|
536
538
|
#
|
537
|
-
#
|
538
|
-
#
|
539
|
-
#
|
540
|
-
#
|
539
|
+
# irb(main):001> 1 + 1
|
540
|
+
# => 2
|
541
|
+
# irb(main):002> 2 + 2
|
542
|
+
# => 4
|
541
543
|
#
|
542
544
|
# The prompt includes:
|
543
545
|
#
|
544
|
-
#
|
545
|
-
#
|
546
|
-
#
|
547
|
-
#
|
548
|
-
#
|
546
|
+
# * The name of the running program (`irb`); see [IRB
|
547
|
+
# Name](rdoc-ref:IRB@IRB+Name).
|
548
|
+
# * The name of the current session (`main`); See [IRB
|
549
|
+
# Sessions](rdoc-ref:IRB@IRB+Sessions).
|
550
|
+
# * A 3-digit line number (1-based).
|
551
|
+
#
|
549
552
|
#
|
550
553
|
# The default prompt actually defines three formats:
|
551
554
|
#
|
552
|
-
#
|
555
|
+
# * One for most situations (as above):
|
553
556
|
#
|
554
|
-
#
|
555
|
-
#
|
557
|
+
# irb(main):003> Dir
|
558
|
+
# => Dir
|
556
559
|
#
|
557
|
-
#
|
560
|
+
# * One for when the typed command is a statement continuation (adds trailing
|
561
|
+
# asterisk):
|
558
562
|
#
|
559
|
-
#
|
563
|
+
# irb(main):004* Dir.
|
560
564
|
#
|
561
|
-
#
|
565
|
+
# * One for when the typed command is a string continuation (adds trailing
|
566
|
+
# single-quote):
|
567
|
+
#
|
568
|
+
# irb(main):005' Dir.entries('.
|
562
569
|
#
|
563
|
-
# irb(main):005' Dir.entries('.
|
564
570
|
#
|
565
571
|
# You can see the prompt change as you type the characters in the following:
|
566
572
|
#
|
@@ -569,258 +575,268 @@ require_relative "irb/pager"
|
|
569
575
|
# irb(main):003> end
|
570
576
|
# => ["README.md", "Rakefile"]
|
571
577
|
#
|
572
|
-
#
|
578
|
+
# #### Pre-Defined Prompts
|
573
579
|
#
|
574
|
-
#
|
580
|
+
# IRB has several pre-defined prompts, stored in hash `IRB.conf[:PROMPT]`:
|
575
581
|
#
|
576
|
-
#
|
577
|
-
#
|
582
|
+
# irb(main):001> IRB.conf[:PROMPT].keys
|
583
|
+
# => [:NULL, :DEFAULT, :CLASSIC, :SIMPLE, :INF_RUBY, :XMP]
|
578
584
|
#
|
579
|
-
# To see the full data for these, type
|
585
|
+
# To see the full data for these, type `IRB.conf[:PROMPT]`.
|
580
586
|
#
|
581
|
-
# Most of these prompt definitions include specifiers that represent
|
582
|
-
#
|
583
|
-
#
|
587
|
+
# Most of these prompt definitions include specifiers that represent values like
|
588
|
+
# the IRB name, session name, and line number; see [Prompt
|
589
|
+
# Specifiers](rdoc-ref:IRB@Prompt+Specifiers).
|
584
590
|
#
|
585
591
|
# You can change the initial prompt and return format by:
|
586
592
|
#
|
587
|
-
#
|
588
|
-
#
|
589
|
-
#
|
593
|
+
# * Adding to the configuration file: `IRB.conf[:PROMPT] = *mode*` where
|
594
|
+
# *mode* is the symbol name of a prompt mode.
|
595
|
+
# * Giving a command-line option:
|
596
|
+
#
|
597
|
+
# * `--prompt *mode*`: sets the prompt mode to *mode*. where *mode* is the
|
598
|
+
# symbol name of a prompt mode.
|
599
|
+
# * `--simple-prompt` or `--sample-book-mode`: sets the prompt mode to
|
600
|
+
# `:SIMPLE`.
|
601
|
+
# * `--inf-ruby-mode`: sets the prompt mode to `:INF_RUBY` and suppresses
|
602
|
+
# both `--multiline` and `--singleline`.
|
603
|
+
# * `--noprompt`: suppresses prompting; does not affect echoing.
|
604
|
+
#
|
590
605
|
#
|
591
|
-
# - <tt>--prompt _mode_</tt>: sets the prompt mode to _mode_.
|
592
|
-
# where _mode_ is the symbol name of a prompt mode.
|
593
|
-
# - <tt>--simple-prompt</tt> or <tt>--sample-book-mode</tt>:
|
594
|
-
# sets the prompt mode to +:SIMPLE+.
|
595
|
-
# - <tt>--inf-ruby-mode</tt>: sets the prompt mode to +:INF_RUBY+
|
596
|
-
# and suppresses both <tt>--multiline</tt> and <tt>--singleline</tt>.
|
597
|
-
# - <tt>--noprompt</tt>: suppresses prompting; does not affect echoing.
|
598
606
|
#
|
599
607
|
# You can retrieve or set the current prompt mode with methods
|
600
608
|
#
|
601
|
-
#
|
609
|
+
# `conf.prompt_mode` and `conf.prompt_mode=`.
|
602
610
|
#
|
603
611
|
# If you're interested in prompts and return formats other than the defaults,
|
604
612
|
# you might experiment by trying some of the others.
|
605
613
|
#
|
606
|
-
#
|
614
|
+
# #### Custom Prompts
|
607
615
|
#
|
608
|
-
# You can also define custom prompts and return formats,
|
609
|
-
#
|
616
|
+
# You can also define custom prompts and return formats, which may be done
|
617
|
+
# either in an IRB session or in the configuration file.
|
610
618
|
#
|
611
|
-
# A prompt in
|
612
|
-
#
|
619
|
+
# A prompt in IRB actually defines three prompts, as seen above. For simple
|
620
|
+
# custom data, we'll make all three the same:
|
613
621
|
#
|
614
|
-
#
|
615
|
-
#
|
616
|
-
#
|
617
|
-
#
|
618
|
-
#
|
619
|
-
#
|
620
|
-
#
|
622
|
+
# irb(main):001* IRB.conf[:PROMPT][:MY_PROMPT] = {
|
623
|
+
# irb(main):002* PROMPT_I: ': ',
|
624
|
+
# irb(main):003* PROMPT_C: ': ',
|
625
|
+
# irb(main):004* PROMPT_S: ': ',
|
626
|
+
# irb(main):005* RETURN: '=> '
|
627
|
+
# irb(main):006> }
|
628
|
+
# => {:PROMPT_I=>": ", :PROMPT_C=>": ", :PROMPT_S=>": ", :RETURN=>"=> "}
|
621
629
|
#
|
622
|
-
# If you define the custom prompt in the configuration file,
|
623
|
-
#
|
630
|
+
# If you define the custom prompt in the configuration file, you can also make
|
631
|
+
# it the current prompt by adding:
|
624
632
|
#
|
625
|
-
#
|
633
|
+
# IRB.conf[:PROMPT_MODE] = :MY_PROMPT
|
626
634
|
#
|
627
|
-
# Regardless of where it's defined, you can make it the current prompt in a
|
635
|
+
# Regardless of where it's defined, you can make it the current prompt in a
|
636
|
+
# session:
|
628
637
|
#
|
629
|
-
#
|
638
|
+
# conf.prompt_mode = :MY_PROMPT
|
630
639
|
#
|
631
|
-
# You can view or modify the current prompt data with various configuration
|
640
|
+
# You can view or modify the current prompt data with various configuration
|
641
|
+
# methods:
|
632
642
|
#
|
633
|
-
#
|
634
|
-
#
|
635
|
-
#
|
636
|
-
#
|
637
|
-
#
|
643
|
+
# * `conf.prompt_mode`, `conf.prompt_mode=`.
|
644
|
+
# * `conf.prompt_c`, `conf.c=`.
|
645
|
+
# * `conf.prompt_i`, `conf.i=`.
|
646
|
+
# * `conf.prompt_s`, `conf.s=`.
|
647
|
+
# * `conf.return_format`, `return_format=`.
|
638
648
|
#
|
639
|
-
# ==== Prompt Specifiers
|
640
649
|
#
|
641
|
-
#
|
650
|
+
# #### Prompt Specifiers
|
642
651
|
#
|
643
|
-
#
|
644
|
-
#
|
645
|
-
# - <tt>%M</tt>: the value of <tt>self.inspect</tt>.
|
646
|
-
# - <tt>%l</tt>: an indication of the type of string;
|
647
|
-
# one of <tt>"</tt>, <tt>'</tt>, <tt>/</tt>, <tt>]</tt>.
|
648
|
-
# - <tt><i>NN</i>i</tt>: Indentation level.
|
649
|
-
# - <tt><i>NN</i>n</tt>: Line number.
|
650
|
-
# - <tt>%%</tt>: Literal <tt>%</tt>.
|
652
|
+
# A prompt's definition can include specifiers for which certain values are
|
653
|
+
# substituted:
|
651
654
|
#
|
652
|
-
#
|
655
|
+
# * `%N`: the name of the running program.
|
656
|
+
# * `%m`: the value of `self.to_s`.
|
657
|
+
# * `%M`: the value of `self.inspect`.
|
658
|
+
# * `%l`: an indication of the type of string; one of `"`, `'`, `/`, `]`.
|
659
|
+
# * `%NNi`: Indentation level. NN is a 2-digit number that specifies the number
|
660
|
+
# of digits of the indentation level (03 will result in 001).
|
661
|
+
# * `%NNn`: Line number. NN is a 2-digit number that specifies the number
|
662
|
+
# of digits of the line number (03 will result in 001).
|
663
|
+
# * `%%`: Literal `%`.
|
653
664
|
#
|
654
|
-
#
|
665
|
+
#
|
666
|
+
# ### Verbosity
|
667
|
+
#
|
668
|
+
# By default, IRB verbosity is disabled, which means that output is smaller
|
655
669
|
# rather than larger.
|
656
670
|
#
|
657
671
|
# You can enable verbosity by:
|
658
672
|
#
|
659
|
-
#
|
660
|
-
#
|
661
|
-
#
|
662
|
-
#
|
673
|
+
# * Adding to the configuration file: `IRB.conf[:VERBOSE] = true` (the default
|
674
|
+
# is `nil`).
|
675
|
+
# * Giving command-line options `--verbose` (the default is `--noverbose`).
|
676
|
+
#
|
663
677
|
#
|
664
678
|
# During a session, you can retrieve or set verbosity with methods
|
665
|
-
#
|
679
|
+
# `conf.verbose` and `conf.verbose=`.
|
666
680
|
#
|
667
|
-
#
|
681
|
+
# ### Help
|
668
682
|
#
|
669
|
-
# Command-line option
|
670
|
-
# and exit.
|
683
|
+
# Command-line option `--version` causes IRB to print its help text and exit.
|
671
684
|
#
|
672
|
-
#
|
685
|
+
# ### Version
|
673
686
|
#
|
674
|
-
# Command-line option
|
675
|
-
# and exit.
|
687
|
+
# Command-line option `--version` causes IRB to print its version text and exit.
|
676
688
|
#
|
677
|
-
#
|
689
|
+
# ## Input and Output
|
678
690
|
#
|
679
|
-
#
|
691
|
+
# ### Color Highlighting
|
680
692
|
#
|
681
|
-
# By default,
|
693
|
+
# By default, IRB color highlighting is enabled, and is used for both:
|
694
|
+
#
|
695
|
+
# * Input: As you type, IRB reads the typed characters and highlights elements
|
696
|
+
# that it recognizes; it also highlights errors such as mismatched
|
697
|
+
# parentheses.
|
698
|
+
# * Output: IRB highlights syntactical elements.
|
682
699
|
#
|
683
|
-
# - Input: As you type, \IRB reads the typed characters and highlights
|
684
|
-
# elements that it recognizes;
|
685
|
-
# it also highlights errors such as mismatched parentheses.
|
686
|
-
# - Output: \IRB highlights syntactical elements.
|
687
700
|
#
|
688
701
|
# You can disable color highlighting by:
|
689
702
|
#
|
690
|
-
#
|
691
|
-
#
|
692
|
-
#
|
703
|
+
# * Adding to the configuration file: `IRB.conf[:USE_COLORIZE] = false` (the
|
704
|
+
# default value is `true`).
|
705
|
+
# * Giving command-line option `--nocolorize`
|
706
|
+
#
|
693
707
|
#
|
694
|
-
#
|
708
|
+
# ## Debugging
|
695
709
|
#
|
696
|
-
# Command-line option
|
697
|
-
#
|
698
|
-
# these have no effect on \IRB output.
|
710
|
+
# Command-line option `-d` sets variables `$VERBOSE` and `$DEBUG` to `true`;
|
711
|
+
# these have no effect on IRB output.
|
699
712
|
#
|
700
|
-
#
|
713
|
+
# ### Warnings
|
701
714
|
#
|
702
|
-
# Command-line option
|
715
|
+
# Command-line option `-w` suppresses warnings.
|
703
716
|
#
|
704
|
-
# Command-line option
|
705
|
-
# sets warning level; 0=silence, 1=medium, 2=verbose.
|
717
|
+
# Command-line option `-W[*level*]` sets warning level;
|
706
718
|
#
|
707
|
-
#
|
719
|
+
# * 0=silence
|
720
|
+
# * 1=medium
|
721
|
+
# * 2=verbose
|
708
722
|
#
|
709
|
-
#
|
723
|
+
# ## Other Features
|
724
|
+
#
|
725
|
+
# ### Load Modules
|
710
726
|
#
|
711
727
|
# You can specify the names of modules that are to be required at startup.
|
712
728
|
#
|
713
|
-
#
|
714
|
-
#
|
715
|
-
#
|
716
|
-
# so the initial value is the only one that counts.
|
729
|
+
# Array `conf.load_modules` determines the modules (if any) that are to be
|
730
|
+
# required during session startup. The array is used only during session
|
731
|
+
# startup, so the initial value is the only one that counts.
|
717
732
|
#
|
718
|
-
# The default initial value is
|
733
|
+
# The default initial value is `[]` (load no modules):
|
719
734
|
#
|
720
|
-
#
|
721
|
-
#
|
735
|
+
# irb(main):001> conf.load_modules
|
736
|
+
# => []
|
722
737
|
#
|
723
738
|
# You can set the default initial value via:
|
724
739
|
#
|
725
|
-
#
|
740
|
+
# * Command-line option `-r`
|
741
|
+
#
|
742
|
+
# $ irb -r csv -r json
|
743
|
+
# irb(main):001> conf.load_modules
|
744
|
+
# => ["csv", "json"]
|
726
745
|
#
|
727
|
-
#
|
728
|
-
# irb(main):001> conf.load_modules
|
729
|
-
# => ["csv", "json"]
|
746
|
+
# * Hash entry `IRB.conf[:LOAD_MODULES] = *array*`:
|
730
747
|
#
|
731
|
-
#
|
748
|
+
# IRB.conf[:LOAD_MODULES] = %w[csv, json]
|
732
749
|
#
|
733
|
-
# IRB.conf[:LOAD_MODULES] = %w[csv, json]
|
734
750
|
#
|
735
751
|
# Note that the configuration file entry overrides the command-line options.
|
736
752
|
#
|
737
|
-
#
|
753
|
+
# ### RI Documentation Directories
|
738
754
|
#
|
739
|
-
# You can specify the paths to RI documentation directories
|
740
|
-
#
|
741
|
-
#
|
755
|
+
# You can specify the paths to RI documentation directories that are to be
|
756
|
+
# loaded (in addition to the default directories) at startup; see details about
|
757
|
+
# RI by typing `ri --help`.
|
742
758
|
#
|
743
|
-
#
|
744
|
-
#
|
745
|
-
# The array is used only during session startup,
|
759
|
+
# Array `conf.extra_doc_dirs` determines the directories (if any) that are to be
|
760
|
+
# loaded during session startup. The array is used only during session startup,
|
746
761
|
# so the initial value is the only one that counts.
|
747
762
|
#
|
748
|
-
# The default initial value is
|
763
|
+
# The default initial value is `[]` (load no extra documentation):
|
749
764
|
#
|
750
|
-
#
|
751
|
-
#
|
765
|
+
# irb(main):001> conf.extra_doc_dirs
|
766
|
+
# => []
|
752
767
|
#
|
753
768
|
# You can set the default initial value via:
|
754
769
|
#
|
755
|
-
#
|
770
|
+
# * Command-line option `--extra_doc_dir`
|
756
771
|
#
|
757
|
-
#
|
758
|
-
#
|
759
|
-
#
|
772
|
+
# $ irb --extra-doc-dir your_doc_dir --extra-doc-dir my_doc_dir
|
773
|
+
# irb(main):001> conf.extra_doc_dirs
|
774
|
+
# => ["your_doc_dir", "my_doc_dir"]
|
760
775
|
#
|
761
|
-
#
|
776
|
+
# * Hash entry `IRB.conf[:EXTRA_DOC_DIRS] = *array*`:
|
777
|
+
#
|
778
|
+
# IRB.conf[:EXTRA_DOC_DIRS] = %w[your_doc_dir my_doc_dir]
|
762
779
|
#
|
763
|
-
# IRB.conf[:EXTRA_DOC_DIRS] = %w[your_doc_dir my_doc_dir]
|
764
780
|
#
|
765
781
|
# Note that the configuration file entry overrides the command-line options.
|
766
782
|
#
|
767
|
-
#
|
783
|
+
# ### IRB Name
|
768
784
|
#
|
769
|
-
# You can specify a name for
|
785
|
+
# You can specify a name for IRB.
|
770
786
|
#
|
771
|
-
# The default initial value is
|
787
|
+
# The default initial value is `'irb'`:
|
772
788
|
#
|
773
|
-
#
|
774
|
-
#
|
789
|
+
# irb(main):001> conf.irb_name
|
790
|
+
# => "irb"
|
775
791
|
#
|
776
|
-
# You can set the default initial value
|
777
|
-
#
|
792
|
+
# You can set the default initial value via hash entry `IRB.conf[:IRB_NAME] =
|
793
|
+
# *string*`:
|
778
794
|
#
|
779
|
-
#
|
795
|
+
# IRB.conf[:IRB_NAME] = 'foo'
|
780
796
|
#
|
781
|
-
#
|
797
|
+
# ### Application Name
|
782
798
|
#
|
783
|
-
# You can specify an application name for the
|
799
|
+
# You can specify an application name for the IRB session.
|
784
800
|
#
|
785
|
-
# The default initial value is
|
801
|
+
# The default initial value is `'irb'`:
|
786
802
|
#
|
787
|
-
#
|
788
|
-
#
|
803
|
+
# irb(main):001> conf.ap_name
|
804
|
+
# => "irb"
|
789
805
|
#
|
790
|
-
# You can set the default initial value
|
791
|
-
#
|
806
|
+
# You can set the default initial value via hash entry `IRB.conf[:AP_NAME] =
|
807
|
+
# *string*`:
|
792
808
|
#
|
793
|
-
#
|
809
|
+
# IRB.conf[:AP_NAME] = 'my_ap_name'
|
794
810
|
#
|
795
|
-
#
|
811
|
+
# ### Configuration Monitor
|
796
812
|
#
|
797
|
-
# You can monitor changes to the configuration by assigning a proc
|
798
|
-
#
|
813
|
+
# You can monitor changes to the configuration by assigning a proc to
|
814
|
+
# `IRB.conf[:IRB_RC]` in the configuration file:
|
799
815
|
#
|
800
|
-
#
|
816
|
+
# IRB.conf[:IRB_RC] = proc {|conf| puts conf.class }
|
801
817
|
#
|
802
|
-
# Each time the configuration is changed,
|
803
|
-
#
|
818
|
+
# Each time the configuration is changed, that proc is called with argument
|
819
|
+
# `conf`:
|
804
820
|
#
|
805
|
-
#
|
821
|
+
# ### Encodings
|
806
822
|
#
|
807
|
-
# Command-line option
|
808
|
-
#
|
823
|
+
# Command-line option `-E *ex*[:*in*]` sets initial external (ex) and internal
|
824
|
+
# (in) encodings.
|
809
825
|
#
|
810
|
-
# Command-line option
|
826
|
+
# Command-line option `-U` sets both to UTF-8.
|
811
827
|
#
|
812
|
-
#
|
828
|
+
# ### Commands
|
813
829
|
#
|
814
830
|
# Please use the `help` command to see the list of available commands.
|
815
831
|
#
|
816
|
-
#
|
832
|
+
# ### IRB Sessions
|
817
833
|
#
|
818
834
|
# IRB has a special feature, that allows you to manage many sessions at once.
|
819
835
|
#
|
820
836
|
# You can create new sessions with Irb.irb, and get a list of current sessions
|
821
|
-
# with the
|
837
|
+
# with the `jobs` command in the prompt.
|
822
838
|
#
|
823
|
-
#
|
839
|
+
# #### Configuration
|
824
840
|
#
|
825
841
|
# The command line options, or IRB.conf, specify the default behavior of
|
826
842
|
# Irb.irb.
|
@@ -828,32 +844,33 @@ require_relative "irb/pager"
|
|
828
844
|
# On the other hand, each conf in IRB@Command-Line+Options is used to
|
829
845
|
# individually configure IRB.irb.
|
830
846
|
#
|
831
|
-
# If a proc is set for
|
847
|
+
# If a proc is set for `IRB.conf[:IRB_RC]`, its will be invoked after execution
|
832
848
|
# of that proc with the context of the current session as its argument. Each
|
833
849
|
# session can be configured using this mechanism.
|
834
850
|
#
|
835
|
-
#
|
851
|
+
# #### Session variables
|
836
852
|
#
|
837
853
|
# There are a few variables in every Irb session that can come in handy:
|
838
854
|
#
|
839
|
-
#
|
840
|
-
# The value command executed, as a local variable
|
841
|
-
#
|
842
|
-
# The history of evaluated commands. Available only if
|
843
|
-
#
|
844
|
-
#
|
845
|
-
#
|
846
|
-
# Returns the evaluation value at the given line number,
|
847
|
-
#
|
848
|
-
#
|
855
|
+
# `_`
|
856
|
+
# : The value command executed, as a local variable
|
857
|
+
# `__`
|
858
|
+
# : The history of evaluated commands. Available only if
|
859
|
+
# `IRB.conf[:EVAL_HISTORY]` is not `nil` (which is the default). See also
|
860
|
+
# IRB::Context#eval_history= and IRB::History.
|
861
|
+
# `__[line_no]`
|
862
|
+
# : Returns the evaluation value at the given line number, `line_no`. If
|
863
|
+
# `line_no` is a negative, the return value `line_no` many lines before the
|
864
|
+
# most recent return value.
|
865
|
+
#
|
849
866
|
#
|
850
|
-
#
|
867
|
+
# ## Restrictions
|
851
868
|
#
|
852
|
-
# Ruby code typed into
|
869
|
+
# Ruby code typed into IRB behaves the same as Ruby code in a file, except that:
|
853
870
|
#
|
854
|
-
#
|
855
|
-
#
|
856
|
-
#
|
871
|
+
# * Because IRB evaluates input immediately after it is syntactically
|
872
|
+
# complete, some results may be slightly different.
|
873
|
+
# * Forking may not be well behaved.
|
857
874
|
#
|
858
875
|
module IRB
|
859
876
|
|
@@ -862,14 +879,14 @@ module IRB
|
|
862
879
|
|
863
880
|
# The current IRB::Context of the session, see IRB.conf
|
864
881
|
#
|
865
|
-
#
|
866
|
-
#
|
867
|
-
#
|
868
|
-
def IRB.CurrentContext
|
882
|
+
# irb
|
883
|
+
# irb(main):001:0> IRB.CurrentContext.irb_name = "foo"
|
884
|
+
# foo(main):002:0> IRB.conf[:MAIN_CONTEXT].irb_name #=> "foo"
|
885
|
+
def IRB.CurrentContext # :nodoc:
|
869
886
|
IRB.conf[:MAIN_CONTEXT]
|
870
887
|
end
|
871
888
|
|
872
|
-
# Initializes IRB and creates a new Irb.irb object at the
|
889
|
+
# Initializes IRB and creates a new Irb.irb object at the `TOPLEVEL_BINDING`
|
873
890
|
def IRB.start(ap_path = nil)
|
874
891
|
STDOUT.sync = true
|
875
892
|
$0 = File::basename(ap_path, ".rb") if ap_path
|
@@ -885,22 +902,22 @@ module IRB
|
|
885
902
|
end
|
886
903
|
|
887
904
|
# Quits irb
|
888
|
-
def IRB.irb_exit(*)
|
905
|
+
def IRB.irb_exit(*) # :nodoc:
|
889
906
|
throw :IRB_EXIT, false
|
890
907
|
end
|
891
908
|
|
892
909
|
# Aborts then interrupts irb.
|
893
910
|
#
|
894
|
-
# Will raise an Abort exception, or the given
|
895
|
-
def IRB.irb_abort(irb, exception = Abort)
|
911
|
+
# Will raise an Abort exception, or the given `exception`.
|
912
|
+
def IRB.irb_abort(irb, exception = Abort) # :nodoc:
|
896
913
|
irb.context.thread.raise exception, "abort then interrupt!"
|
897
914
|
end
|
898
915
|
|
899
916
|
class Irb
|
900
917
|
# Note: instance and index assignment expressions could also be written like:
|
901
|
-
# "foo.bar=(1)" and "foo.[]=(1, bar)", when expressed that way, the former
|
902
|
-
#
|
903
|
-
#
|
918
|
+
# "foo.bar=(1)" and "foo.[]=(1, bar)", when expressed that way, the former be
|
919
|
+
# parsed as :assign and echo will be suppressed, but the latter is parsed as a
|
920
|
+
# :method_add_arg and the output won't be suppressed
|
904
921
|
|
905
922
|
PROMPT_MAIN_TRUNCATE_LENGTH = 32
|
906
923
|
PROMPT_MAIN_TRUNCATE_OMISSION = '...'
|
@@ -914,13 +931,14 @@ module IRB
|
|
914
931
|
# Creates a new irb session
|
915
932
|
def initialize(workspace = nil, input_method = nil)
|
916
933
|
@context = Context.new(self, workspace, input_method)
|
917
|
-
@context.workspace.
|
934
|
+
@context.workspace.load_helper_methods_to_main
|
918
935
|
@signal_status = :IN_IRB
|
919
936
|
@scanner = RubyLex.new
|
920
937
|
@line_no = 1
|
921
938
|
end
|
922
939
|
|
923
|
-
# A hook point for `debug` command's breakpoint after :IRB_EXIT as well as its
|
940
|
+
# A hook point for `debug` command's breakpoint after :IRB_EXIT as well as its
|
941
|
+
# clean-up
|
924
942
|
def debug_break
|
925
943
|
# it means the debug integration has been activated
|
926
944
|
if defined?(DEBUGGER__) && DEBUGGER__.respond_to?(:capture_frames_without_irb)
|
@@ -934,28 +952,36 @@ module IRB
|
|
934
952
|
def debug_readline(binding)
|
935
953
|
workspace = IRB::WorkSpace.new(binding)
|
936
954
|
context.replace_workspace(workspace)
|
937
|
-
context.workspace.
|
955
|
+
context.workspace.load_helper_methods_to_main
|
938
956
|
@line_no += 1
|
939
957
|
|
940
958
|
# When users run:
|
941
|
-
# 1.
|
942
|
-
# 2.
|
959
|
+
# 1. Debugging commands, like `step 2`
|
960
|
+
# 2. Any input that's not irb-command, like `foo = 123`
|
961
|
+
#
|
943
962
|
#
|
944
|
-
# Irb#eval_input will simply return the input, and we need to pass it to the
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
context.io.
|
963
|
+
# Irb#eval_input will simply return the input, and we need to pass it to the
|
964
|
+
# debugger.
|
965
|
+
input = nil
|
966
|
+
forced_exit = catch(:IRB_EXIT) do
|
967
|
+
if IRB.conf[:SAVE_HISTORY] && context.io.support_history_saving?
|
968
|
+
# Previous IRB session's history has been saved when `Irb#run` is exited We need
|
969
|
+
# to make sure the saved history is not saved again by resetting the counter
|
970
|
+
context.io.reset_history_counter
|
949
971
|
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
972
|
+
begin
|
973
|
+
input = eval_input
|
974
|
+
ensure
|
975
|
+
context.io.save_history
|
976
|
+
end
|
977
|
+
else
|
978
|
+
input = eval_input
|
954
979
|
end
|
955
|
-
|
956
|
-
eval_input
|
980
|
+
false
|
957
981
|
end
|
958
982
|
|
983
|
+
Kernel.exit if forced_exit
|
984
|
+
|
959
985
|
if input&.include?("\n")
|
960
986
|
@line_no += input.count("\n") - 1
|
961
987
|
end
|
@@ -966,6 +992,7 @@ module IRB
|
|
966
992
|
def run(conf = IRB.conf)
|
967
993
|
in_nested_session = !!conf[:MAIN_CONTEXT]
|
968
994
|
conf[:IRB_RC].call(context) if conf[:IRB_RC]
|
995
|
+
prev_context = conf[:MAIN_CONTEXT]
|
969
996
|
conf[:MAIN_CONTEXT] = context
|
970
997
|
|
971
998
|
save_history = !in_nested_session && conf[:SAVE_HISTORY] && context.io.support_history_saving?
|
@@ -988,6 +1015,9 @@ module IRB
|
|
988
1015
|
eval_input
|
989
1016
|
end
|
990
1017
|
ensure
|
1018
|
+
# Do not restore to nil. It will cause IRB crash when used with threads.
|
1019
|
+
IRB.conf[:MAIN_CONTEXT] = prev_context if prev_context
|
1020
|
+
|
991
1021
|
RubyVM.keep_script_lines = keep_script_lines_backup if defined?(RubyVM.keep_script_lines)
|
992
1022
|
trap("SIGINT", prev_trap)
|
993
1023
|
conf[:AT_EXIT].each{|hook| hook.call}
|
@@ -1004,12 +1034,13 @@ module IRB
|
|
1004
1034
|
each_top_level_statement do |statement, line_no|
|
1005
1035
|
signal_status(:IN_EVAL) do
|
1006
1036
|
begin
|
1007
|
-
# If the integration with debugger is activated, we return certain input if it
|
1037
|
+
# If the integration with debugger is activated, we return certain input if it
|
1038
|
+
# should be dealt with by debugger
|
1008
1039
|
if @context.with_debugger && statement.should_be_handled_by_debugger?
|
1009
1040
|
return statement.code
|
1010
1041
|
end
|
1011
1042
|
|
1012
|
-
@context.evaluate(statement
|
1043
|
+
@context.evaluate(statement, line_no)
|
1013
1044
|
|
1014
1045
|
if @context.echo? && !statement.suppresses_echo?
|
1015
1046
|
if statement.is_assignment?
|
@@ -1065,9 +1096,7 @@ module IRB
|
|
1065
1096
|
end
|
1066
1097
|
|
1067
1098
|
code << line
|
1068
|
-
|
1069
|
-
# Accept any single-line input for symbol aliases or commands that transform args
|
1070
|
-
return code if single_line_command?(code)
|
1099
|
+
return code if command?(code)
|
1071
1100
|
|
1072
1101
|
tokens, opens, terminated = @scanner.check_code_state(code, local_variables: @context.local_variables)
|
1073
1102
|
return code if terminated
|
@@ -1094,23 +1123,36 @@ module IRB
|
|
1094
1123
|
end
|
1095
1124
|
|
1096
1125
|
code.force_encoding(@context.io.encoding)
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
command = command_name || command_or_alias
|
1101
|
-
command_class = ExtendCommandBundle.load_command(command)
|
1102
|
-
|
1103
|
-
if command_class
|
1104
|
-
Statement::Command.new(code, command, arg, command_class)
|
1126
|
+
if (command, arg = parse_command(code))
|
1127
|
+
command_class = Command.load_command(command)
|
1128
|
+
Statement::Command.new(code, command_class, arg)
|
1105
1129
|
else
|
1106
1130
|
is_assignment_expression = @scanner.assignment_expression?(code, local_variables: @context.local_variables)
|
1107
1131
|
Statement::Expression.new(code, is_assignment_expression)
|
1108
1132
|
end
|
1109
1133
|
end
|
1110
1134
|
|
1111
|
-
def
|
1112
|
-
|
1113
|
-
|
1135
|
+
def parse_command(code)
|
1136
|
+
command_name, arg = code.strip.split(/\s+/, 2)
|
1137
|
+
return unless code.lines.size == 1 && command_name
|
1138
|
+
|
1139
|
+
arg ||= ''
|
1140
|
+
command = command_name.to_sym
|
1141
|
+
# Command aliases are always command. example: $, @
|
1142
|
+
if (alias_name = @context.command_aliases[command])
|
1143
|
+
return [alias_name, arg]
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
# Check visibility
|
1147
|
+
public_method = !!Kernel.instance_method(:public_method).bind_call(@context.main, command) rescue false
|
1148
|
+
private_method = !public_method && !!Kernel.instance_method(:method).bind_call(@context.main, command) rescue false
|
1149
|
+
if Command.execute_as_command?(command, public_method: public_method, private_method: private_method)
|
1150
|
+
[command, arg]
|
1151
|
+
end
|
1152
|
+
end
|
1153
|
+
|
1154
|
+
def command?(code)
|
1155
|
+
!!parse_command(code)
|
1114
1156
|
end
|
1115
1157
|
|
1116
1158
|
def configure_io
|
@@ -1128,8 +1170,7 @@ module IRB
|
|
1128
1170
|
false
|
1129
1171
|
end
|
1130
1172
|
else
|
1131
|
-
|
1132
|
-
next true if single_line_command?(code)
|
1173
|
+
next true if command?(code)
|
1133
1174
|
|
1134
1175
|
_tokens, _opens, terminated = @scanner.check_code_state(code, local_variables: @context.local_variables)
|
1135
1176
|
terminated
|
@@ -1143,7 +1184,8 @@ module IRB
|
|
1143
1184
|
tokens_until_line = []
|
1144
1185
|
line_results.map.with_index do |(line_tokens, _prev_opens, next_opens, _min_depth), line_num_offset|
|
1145
1186
|
line_tokens.each do |token, _s|
|
1146
|
-
# Avoid appending duplicated token. Tokens that include "
|
1187
|
+
# Avoid appending duplicated token. Tokens that include "n" like multiline
|
1188
|
+
# tstring_content can exist in multiple lines.
|
1147
1189
|
tokens_until_line << token if token != tokens_until_line.last
|
1148
1190
|
end
|
1149
1191
|
continue = @scanner.should_continue?(tokens_until_line)
|
@@ -1200,20 +1242,33 @@ module IRB
|
|
1200
1242
|
irb_bug = true
|
1201
1243
|
else
|
1202
1244
|
irb_bug = false
|
1245
|
+
# To support backtrace filtering while utilizing Exception#full_message, we need to clone
|
1246
|
+
# the exception to avoid modifying the original exception's backtrace.
|
1247
|
+
exc = exc.clone
|
1248
|
+
filtered_backtrace = exc.backtrace.map { |l| @context.workspace.filter_backtrace(l) }.compact
|
1249
|
+
backtrace_filter = IRB.conf[:BACKTRACE_FILTER]
|
1250
|
+
|
1251
|
+
if backtrace_filter
|
1252
|
+
if backtrace_filter.respond_to?(:call)
|
1253
|
+
filtered_backtrace = backtrace_filter.call(filtered_backtrace)
|
1254
|
+
else
|
1255
|
+
warn "IRB.conf[:BACKTRACE_FILTER] #{backtrace_filter} should respond to `call` method"
|
1256
|
+
end
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
exc.set_backtrace(filtered_backtrace)
|
1203
1260
|
end
|
1204
1261
|
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1262
|
+
highlight = Color.colorable?
|
1263
|
+
|
1264
|
+
order =
|
1265
|
+
if RUBY_VERSION < '3.0.0'
|
1266
|
+
STDOUT.tty? ? :bottom : :top
|
1267
|
+
else # '3.0.0' <= RUBY_VERSION
|
1268
|
+
:top
|
1212
1269
|
end
|
1213
|
-
|
1214
|
-
|
1215
|
-
order = :top
|
1216
|
-
end
|
1270
|
+
|
1271
|
+
message = exc.full_message(order: order, highlight: highlight)
|
1217
1272
|
message = convert_invalid_byte_sequence(message, exc.message.encoding)
|
1218
1273
|
message = encode_with_invalid_byte_sequence(message, IRB.conf[:LC_MESSAGES].encoding) unless message.encoding.to_s.casecmp?(IRB.conf[:LC_MESSAGES].encoding.to_s)
|
1219
1274
|
message = message.gsub(/((?:^\t.+$\n)+)/) { |m|
|
@@ -1224,7 +1279,6 @@ module IRB
|
|
1224
1279
|
lines = m.split("\n").reverse
|
1225
1280
|
end
|
1226
1281
|
unless irb_bug
|
1227
|
-
lines = lines.map { |l| @context.workspace.filter_backtrace(l) }.compact
|
1228
1282
|
if lines.size > @context.back_trace_limit
|
1229
1283
|
omit = lines.size - @context.back_trace_limit
|
1230
1284
|
lines = lines[0..(@context.back_trace_limit - 1)]
|
@@ -1247,11 +1301,10 @@ module IRB
|
|
1247
1301
|
end
|
1248
1302
|
end
|
1249
1303
|
|
1250
|
-
# Evaluates the given block using the given
|
1251
|
-
#
|
1304
|
+
# Evaluates the given block using the given `path` as the Context#irb_path and
|
1305
|
+
# `name` as the Context#irb_name.
|
1252
1306
|
#
|
1253
|
-
# Used by the irb command
|
1254
|
-
# information.
|
1307
|
+
# Used by the irb command `source`, see IRB@IRB+Sessions for more information.
|
1255
1308
|
def suspend_name(path = nil, name = nil)
|
1256
1309
|
@context.irb_path, back_path = path, @context.irb_path if path
|
1257
1310
|
@context.irb_name, back_name = name, @context.irb_name if name
|
@@ -1263,11 +1316,10 @@ module IRB
|
|
1263
1316
|
end
|
1264
1317
|
end
|
1265
1318
|
|
1266
|
-
# Evaluates the given block using the given
|
1319
|
+
# Evaluates the given block using the given `workspace` as the
|
1267
1320
|
# Context#workspace.
|
1268
1321
|
#
|
1269
|
-
# Used by the irb command
|
1270
|
-
# information.
|
1322
|
+
# Used by the irb command `irb_load`, see IRB@IRB+Sessions for more information.
|
1271
1323
|
def suspend_workspace(workspace)
|
1272
1324
|
current_workspace = @context.workspace
|
1273
1325
|
@context.replace_workspace(workspace)
|
@@ -1276,11 +1328,10 @@ module IRB
|
|
1276
1328
|
@context.replace_workspace current_workspace
|
1277
1329
|
end
|
1278
1330
|
|
1279
|
-
# Evaluates the given block using the given
|
1280
|
-
# Context#io.
|
1331
|
+
# Evaluates the given block using the given `input_method` as the Context#io.
|
1281
1332
|
#
|
1282
|
-
# Used by the irb commands
|
1283
|
-
#
|
1333
|
+
# Used by the irb commands `source` and `irb_load`, see IRB@IRB+Sessions for
|
1334
|
+
# more information.
|
1284
1335
|
def suspend_input_method(input_method)
|
1285
1336
|
back_io = @context.io
|
1286
1337
|
@context.instance_eval{@io = input_method}
|
@@ -1313,7 +1364,7 @@ module IRB
|
|
1313
1364
|
end
|
1314
1365
|
end
|
1315
1366
|
|
1316
|
-
# Evaluates the given block using the given
|
1367
|
+
# Evaluates the given block using the given `status`.
|
1317
1368
|
def signal_status(status)
|
1318
1369
|
return yield if @signal_status == :IN_LOAD
|
1319
1370
|
|
@@ -1363,8 +1414,8 @@ module IRB
|
|
1363
1414
|
Pager.page_content(format(@context.return_format, str), retain_content: true)
|
1364
1415
|
end
|
1365
1416
|
|
1366
|
-
# Outputs the local variables to this current session, including
|
1367
|
-
#
|
1417
|
+
# Outputs the local variables to this current session, including #signal_status
|
1418
|
+
# and #context, using IRB::Locale.
|
1368
1419
|
def inspect
|
1369
1420
|
ary = []
|
1370
1421
|
for iv in instance_variables
|
@@ -1422,7 +1473,7 @@ module IRB
|
|
1422
1473
|
end
|
1423
1474
|
|
1424
1475
|
def format_prompt(format, ltype, indent, line_no) # :nodoc:
|
1425
|
-
format.gsub(/%([0-9]+)?([a-zA-Z])/) do
|
1476
|
+
format.gsub(/%([0-9]+)?([a-zA-Z%])/) do
|
1426
1477
|
case $2
|
1427
1478
|
when "N"
|
1428
1479
|
@context.irb_name
|
@@ -1455,7 +1506,7 @@ module IRB
|
|
1455
1506
|
line_no.to_s
|
1456
1507
|
end
|
1457
1508
|
when "%"
|
1458
|
-
"%"
|
1509
|
+
"%" unless $1
|
1459
1510
|
end
|
1460
1511
|
end
|
1461
1512
|
end
|
@@ -1463,12 +1514,11 @@ module IRB
|
|
1463
1514
|
end
|
1464
1515
|
|
1465
1516
|
class Binding
|
1466
|
-
# Opens an IRB session where
|
1467
|
-
# interactive debugging. You can call any methods or variables available in
|
1468
|
-
#
|
1469
|
-
#
|
1517
|
+
# Opens an IRB session where `binding.irb` is called which allows for
|
1518
|
+
# interactive debugging. You can call any methods or variables available in the
|
1519
|
+
# current scope, and mutate state if you need to.
|
1470
1520
|
#
|
1471
|
-
# Given a Ruby file called
|
1521
|
+
# Given a Ruby file called `potato.rb` containing the following code:
|
1472
1522
|
#
|
1473
1523
|
# class Potato
|
1474
1524
|
# def initialize
|
@@ -1480,8 +1530,8 @@ class Binding
|
|
1480
1530
|
#
|
1481
1531
|
# Potato.new
|
1482
1532
|
#
|
1483
|
-
# Running
|
1484
|
-
#
|
1533
|
+
# Running `ruby potato.rb` will open an IRB session where `binding.irb` is
|
1534
|
+
# called, and you will see the following:
|
1485
1535
|
#
|
1486
1536
|
# $ ruby potato.rb
|
1487
1537
|
#
|
@@ -1511,8 +1561,8 @@ class Binding
|
|
1511
1561
|
# irb(#<Potato:0x00007feea1916670>):004:0> @cooked = true
|
1512
1562
|
# => true
|
1513
1563
|
#
|
1514
|
-
# You can exit the IRB session with the
|
1515
|
-
# resume execution where
|
1564
|
+
# You can exit the IRB session with the `exit` command. Note that exiting will
|
1565
|
+
# resume execution where `binding.irb` had paused it, as you can see from the
|
1516
1566
|
# output printed to standard output in this example:
|
1517
1567
|
#
|
1518
1568
|
# irb(#<Potato:0x00007feea1916670>):005:0> exit
|
@@ -1535,13 +1585,14 @@ class Binding
|
|
1535
1585
|
# If we're already in a debugger session, set the workspace and irb_path for the original IRB instance
|
1536
1586
|
debugger_irb.context.replace_workspace(workspace)
|
1537
1587
|
debugger_irb.context.irb_path = irb_path
|
1538
|
-
# If we've started a debugger session and hit another binding.irb, we don't want
|
1539
|
-
# instead, we want to resume the irb:rdbg session.
|
1588
|
+
# If we've started a debugger session and hit another binding.irb, we don't want
|
1589
|
+
# to start an IRB session instead, we want to resume the irb:rdbg session.
|
1540
1590
|
IRB::Debug.setup(debugger_irb)
|
1541
1591
|
IRB::Debug.insert_debug_break
|
1542
1592
|
debugger_irb.debug_break
|
1543
1593
|
else
|
1544
|
-
# If we're not in a debugger session, create a new IRB instance with the current
|
1594
|
+
# If we're not in a debugger session, create a new IRB instance with the current
|
1595
|
+
# workspace
|
1545
1596
|
binding_irb = IRB::Irb.new(workspace)
|
1546
1597
|
binding_irb.context.irb_path = irb_path
|
1547
1598
|
binding_irb.run(IRB.conf)
|