irb 1.11.2 → 1.12.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 +10 -8
- data/lib/irb/cmd/nop.rb +3 -52
- data/lib/irb/{cmd → command}/backtrace.rb +1 -1
- data/lib/irb/command/base.rb +64 -0
- data/lib/irb/{cmd → command}/break.rb +1 -1
- data/lib/irb/{cmd → command}/catch.rb +1 -1
- data/lib/irb/{cmd → command}/chws.rb +4 -6
- data/lib/irb/{cmd → command}/continue.rb +1 -1
- data/lib/irb/{cmd → command}/debug.rb +3 -4
- data/lib/irb/{cmd → command}/delete.rb +1 -1
- data/lib/irb/command/edit.rb +70 -0
- data/lib/irb/{cmd → command}/exit.rb +2 -4
- data/lib/irb/{cmd → command}/finish.rb +1 -1
- data/lib/irb/command/force_exit.rb +20 -0
- data/lib/irb/command/help.rb +84 -0
- data/lib/irb/{cmd → command}/history.rb +3 -3
- data/lib/irb/{cmd → command}/info.rb +1 -1
- data/lib/irb/{cmd → command}/irb_info.rb +5 -6
- data/lib/irb/{cmd → command}/load.rb +3 -5
- data/lib/irb/{cmd → command}/ls.rb +10 -4
- data/lib/irb/{cmd → command}/measure.rb +2 -4
- data/lib/irb/{cmd → command}/next.rb +1 -1
- data/lib/irb/{cmd → command}/pushws.rb +20 -5
- data/lib/irb/{cmd → command}/show_doc.rb +17 -5
- data/lib/irb/{cmd → command}/show_source.rb +26 -10
- data/lib/irb/{cmd → command}/step.rb +1 -1
- data/lib/irb/{cmd → command}/subirb.rb +3 -5
- data/lib/irb/{cmd → command}/whereami.rb +2 -4
- data/lib/irb/{extend-command.rb → command.rb} +50 -85
- data/lib/irb/completion.rb +1 -1
- data/lib/irb/context.rb +56 -18
- data/lib/irb/ext/change-ws.rb +4 -4
- data/lib/irb/ext/eval_history.rb +3 -3
- data/lib/irb/ext/loader.rb +4 -4
- data/lib/irb/ext/multi-irb.rb +1 -1
- data/lib/irb/ext/tracer.rb +1 -1
- data/lib/irb/ext/use-loader.rb +6 -8
- data/lib/irb/ext/workspaces.rb +11 -34
- data/lib/irb/frame.rb +1 -1
- data/lib/irb/help.rb +1 -1
- data/lib/irb/history.rb +2 -2
- data/lib/irb/init.rb +22 -14
- data/lib/irb/input-method.rb +18 -2
- data/lib/irb/inspector.rb +2 -2
- data/lib/irb/lc/error.rb +1 -6
- data/lib/irb/lc/ja/error.rb +1 -6
- data/lib/irb/locale.rb +1 -1
- data/lib/irb/notifier.rb +1 -1
- data/lib/irb/output-method.rb +2 -8
- data/lib/irb/ruby-lex.rb +1 -1
- data/lib/irb/source_finder.rb +98 -38
- data/lib/irb/statement.rb +25 -3
- data/lib/irb/version.rb +3 -3
- data/lib/irb/workspace.rb +4 -4
- data/lib/irb/ws-for-case-2.rb +1 -1
- data/lib/irb/xmp.rb +1 -1
- data/lib/irb.rb +29 -22
- metadata +30 -29
- data/lib/irb/cmd/edit.rb +0 -60
- data/lib/irb/cmd/help.rb +0 -23
- data/lib/irb/cmd/show_cmds.rb +0 -59
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "nop"
|
4
|
-
|
5
3
|
module IRB
|
6
|
-
module
|
7
|
-
class ShowDoc <
|
4
|
+
module Command
|
5
|
+
class ShowDoc < Base
|
8
6
|
class << self
|
9
7
|
def transform_args(args)
|
10
8
|
# Return a string literal as is for backward compatibility
|
@@ -17,7 +15,21 @@ module IRB
|
|
17
15
|
end
|
18
16
|
|
19
17
|
category "Context"
|
20
|
-
description "
|
18
|
+
description "Look up documentation with RI."
|
19
|
+
|
20
|
+
help_message <<~HELP_MESSAGE
|
21
|
+
Usage: show_doc [name]
|
22
|
+
|
23
|
+
When name is provided, IRB will look up the documentation for the given name.
|
24
|
+
When no name is provided, a RI session will be started.
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
|
28
|
+
show_doc
|
29
|
+
show_doc Array
|
30
|
+
show_doc Array#each
|
31
|
+
|
32
|
+
HELP_MESSAGE
|
21
33
|
|
22
34
|
def execute(*names)
|
23
35
|
require 'rdoc/ri/driver'
|
@@ -1,15 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "nop"
|
4
3
|
require_relative "../source_finder"
|
5
4
|
require_relative "../pager"
|
6
5
|
require_relative "../color"
|
7
6
|
|
8
7
|
module IRB
|
9
|
-
module
|
10
|
-
class ShowSource <
|
8
|
+
module Command
|
9
|
+
class ShowSource < Base
|
11
10
|
category "Context"
|
12
|
-
description "Show the source code of a given method or constant."
|
11
|
+
description "Show the source code of a given method, class/module, or constant."
|
12
|
+
|
13
|
+
help_message <<~HELP_MESSAGE
|
14
|
+
Usage: show_source [target] [-s]
|
15
|
+
|
16
|
+
-s Show the super method. You can stack it like `-ss` to show the super of the super, etc.
|
17
|
+
|
18
|
+
Examples:
|
19
|
+
|
20
|
+
show_source Foo
|
21
|
+
show_source Foo#bar
|
22
|
+
show_source Foo#bar -s
|
23
|
+
show_source Foo.baz
|
24
|
+
show_source Foo::BAR
|
25
|
+
HELP_MESSAGE
|
13
26
|
|
14
27
|
class << self
|
15
28
|
def transform_args(args)
|
@@ -45,15 +58,18 @@ module IRB
|
|
45
58
|
private
|
46
59
|
|
47
60
|
def show_source(source)
|
48
|
-
|
49
|
-
|
50
|
-
|
61
|
+
if source.binary_file?
|
62
|
+
content = "\n#{bold('Defined in binary file')}: #{source.file}\n\n"
|
63
|
+
else
|
64
|
+
code = source.colorized_content || 'Source not available'
|
65
|
+
content = <<~CONTENT
|
51
66
|
|
52
|
-
|
67
|
+
#{bold("From")}: #{source.file}:#{source.line}
|
53
68
|
|
54
|
-
|
55
|
-
CONTENT
|
69
|
+
#{code.chomp}
|
56
70
|
|
71
|
+
CONTENT
|
72
|
+
end
|
57
73
|
Pager.page_content(content)
|
58
74
|
end
|
59
75
|
|
@@ -1,16 +1,14 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# multi.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
5
|
#
|
6
6
|
|
7
|
-
require_relative "nop"
|
8
|
-
|
9
7
|
module IRB
|
10
8
|
# :stopdoc:
|
11
9
|
|
12
|
-
module
|
13
|
-
class MultiIRBCommand <
|
10
|
+
module Command
|
11
|
+
class MultiIRBCommand < Base
|
14
12
|
def execute(*args)
|
15
13
|
extend_irb_context
|
16
14
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "nop"
|
4
|
-
|
5
3
|
module IRB
|
6
4
|
# :stopdoc:
|
7
5
|
|
8
|
-
module
|
9
|
-
class Whereami <
|
6
|
+
module Command
|
7
|
+
class Whereami < Base
|
10
8
|
category "Context"
|
11
9
|
description "Show the source code around binding.irb again."
|
12
10
|
|
@@ -1,10 +1,15 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# irb/
|
3
|
+
# irb/command.rb - irb command
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
5
5
|
#
|
6
6
|
|
7
|
+
require_relative "command/base"
|
8
|
+
|
7
9
|
module IRB # :nodoc:
|
10
|
+
module Command; end
|
11
|
+
ExtendCommand = Command
|
12
|
+
|
8
13
|
# Installs the default irb extensions command bundle.
|
9
14
|
module ExtendCommandBundle
|
10
15
|
EXCB = ExtendCommandBundle # :nodoc:
|
@@ -31,13 +36,18 @@ module IRB # :nodoc:
|
|
31
36
|
|
32
37
|
@EXTEND_COMMANDS = [
|
33
38
|
[
|
34
|
-
:irb_exit, :Exit, "
|
39
|
+
:irb_exit, :Exit, "command/exit",
|
35
40
|
[:exit, OVERRIDE_PRIVATE_ONLY],
|
36
41
|
[:quit, OVERRIDE_PRIVATE_ONLY],
|
37
42
|
[:irb_quit, OVERRIDE_PRIVATE_ONLY],
|
38
43
|
],
|
39
44
|
[
|
40
|
-
:
|
45
|
+
:irb_exit!, :ForceExit, "command/force_exit",
|
46
|
+
[:exit!, OVERRIDE_PRIVATE_ONLY],
|
47
|
+
],
|
48
|
+
|
49
|
+
[
|
50
|
+
:irb_current_working_workspace, :CurrentWorkingWorkspace, "command/chws",
|
41
51
|
[:cwws, NO_OVERRIDE],
|
42
52
|
[:pwws, NO_OVERRIDE],
|
43
53
|
[:irb_print_working_workspace, OVERRIDE_ALL],
|
@@ -49,7 +59,7 @@ module IRB # :nodoc:
|
|
49
59
|
[:irb_pwb, OVERRIDE_ALL],
|
50
60
|
],
|
51
61
|
[
|
52
|
-
:irb_change_workspace, :ChangeWorkspace, "
|
62
|
+
:irb_change_workspace, :ChangeWorkspace, "command/chws",
|
53
63
|
[:chws, NO_OVERRIDE],
|
54
64
|
[:cws, NO_OVERRIDE],
|
55
65
|
[:irb_chws, OVERRIDE_ALL],
|
@@ -60,13 +70,13 @@ module IRB # :nodoc:
|
|
60
70
|
],
|
61
71
|
|
62
72
|
[
|
63
|
-
:irb_workspaces, :Workspaces, "
|
73
|
+
:irb_workspaces, :Workspaces, "command/pushws",
|
64
74
|
[:workspaces, NO_OVERRIDE],
|
65
75
|
[:irb_bindings, OVERRIDE_ALL],
|
66
76
|
[:bindings, NO_OVERRIDE],
|
67
77
|
],
|
68
78
|
[
|
69
|
-
:irb_push_workspace, :PushWorkspace, "
|
79
|
+
:irb_push_workspace, :PushWorkspace, "command/pushws",
|
70
80
|
[:pushws, NO_OVERRIDE],
|
71
81
|
[:irb_pushws, OVERRIDE_ALL],
|
72
82
|
[:irb_push_binding, OVERRIDE_ALL],
|
@@ -74,7 +84,7 @@ module IRB # :nodoc:
|
|
74
84
|
[:pushb, NO_OVERRIDE],
|
75
85
|
],
|
76
86
|
[
|
77
|
-
:irb_pop_workspace, :PopWorkspace, "
|
87
|
+
:irb_pop_workspace, :PopWorkspace, "command/pushws",
|
78
88
|
[:popws, NO_OVERRIDE],
|
79
89
|
[:irb_popws, OVERRIDE_ALL],
|
80
90
|
[:irb_pop_binding, OVERRIDE_ALL],
|
@@ -83,112 +93,107 @@ module IRB # :nodoc:
|
|
83
93
|
],
|
84
94
|
|
85
95
|
[
|
86
|
-
:irb_load, :Load, "
|
96
|
+
:irb_load, :Load, "command/load"],
|
87
97
|
[
|
88
|
-
:irb_require, :Require, "
|
98
|
+
:irb_require, :Require, "command/load"],
|
89
99
|
[
|
90
|
-
:irb_source, :Source, "
|
100
|
+
:irb_source, :Source, "command/load",
|
91
101
|
[:source, NO_OVERRIDE],
|
92
102
|
],
|
93
103
|
|
94
104
|
[
|
95
|
-
:irb, :IrbCommand, "
|
105
|
+
:irb, :IrbCommand, "command/subirb"],
|
96
106
|
[
|
97
|
-
:irb_jobs, :Jobs, "
|
107
|
+
:irb_jobs, :Jobs, "command/subirb",
|
98
108
|
[:jobs, NO_OVERRIDE],
|
99
109
|
],
|
100
110
|
[
|
101
|
-
:irb_fg, :Foreground, "
|
111
|
+
:irb_fg, :Foreground, "command/subirb",
|
102
112
|
[:fg, NO_OVERRIDE],
|
103
113
|
],
|
104
114
|
[
|
105
|
-
:irb_kill, :Kill, "
|
115
|
+
:irb_kill, :Kill, "command/subirb",
|
106
116
|
[:kill, OVERRIDE_PRIVATE_ONLY],
|
107
117
|
],
|
108
118
|
|
109
119
|
[
|
110
|
-
:irb_debug, :Debug, "
|
120
|
+
:irb_debug, :Debug, "command/debug",
|
111
121
|
[:debug, NO_OVERRIDE],
|
112
122
|
],
|
113
123
|
[
|
114
|
-
:irb_edit, :Edit, "
|
124
|
+
:irb_edit, :Edit, "command/edit",
|
115
125
|
[:edit, NO_OVERRIDE],
|
116
126
|
],
|
117
127
|
[
|
118
|
-
:irb_break, :Break, "
|
128
|
+
:irb_break, :Break, "command/break",
|
119
129
|
],
|
120
130
|
[
|
121
|
-
:irb_catch, :Catch, "
|
131
|
+
:irb_catch, :Catch, "command/catch",
|
122
132
|
],
|
123
133
|
[
|
124
|
-
:irb_next, :Next, "
|
134
|
+
:irb_next, :Next, "command/next"
|
125
135
|
],
|
126
136
|
[
|
127
|
-
:irb_delete, :Delete, "
|
137
|
+
:irb_delete, :Delete, "command/delete",
|
128
138
|
[:delete, NO_OVERRIDE],
|
129
139
|
],
|
130
140
|
[
|
131
|
-
:irb_step, :Step, "
|
141
|
+
:irb_step, :Step, "command/step",
|
132
142
|
[:step, NO_OVERRIDE],
|
133
143
|
],
|
134
144
|
[
|
135
|
-
:irb_continue, :Continue, "
|
145
|
+
:irb_continue, :Continue, "command/continue",
|
136
146
|
[:continue, NO_OVERRIDE],
|
137
147
|
],
|
138
148
|
[
|
139
|
-
:irb_finish, :Finish, "
|
149
|
+
:irb_finish, :Finish, "command/finish",
|
140
150
|
[:finish, NO_OVERRIDE],
|
141
151
|
],
|
142
152
|
[
|
143
|
-
:irb_backtrace, :Backtrace, "
|
153
|
+
:irb_backtrace, :Backtrace, "command/backtrace",
|
144
154
|
[:backtrace, NO_OVERRIDE],
|
145
155
|
[:bt, NO_OVERRIDE],
|
146
156
|
],
|
147
157
|
[
|
148
|
-
:irb_debug_info, :Info, "
|
158
|
+
:irb_debug_info, :Info, "command/info",
|
149
159
|
[:info, NO_OVERRIDE],
|
150
160
|
],
|
151
161
|
|
152
162
|
[
|
153
|
-
:irb_help, :Help, "
|
163
|
+
:irb_help, :Help, "command/help",
|
154
164
|
[:help, NO_OVERRIDE],
|
165
|
+
[:show_cmds, NO_OVERRIDE],
|
155
166
|
],
|
156
167
|
|
157
168
|
[
|
158
|
-
:irb_show_doc, :ShowDoc, "
|
169
|
+
:irb_show_doc, :ShowDoc, "command/show_doc",
|
159
170
|
[:show_doc, NO_OVERRIDE],
|
160
171
|
],
|
161
172
|
|
162
173
|
[
|
163
|
-
:irb_info, :IrbInfo, "
|
174
|
+
:irb_info, :IrbInfo, "command/irb_info"
|
164
175
|
],
|
165
176
|
|
166
177
|
[
|
167
|
-
:irb_ls, :Ls, "
|
178
|
+
:irb_ls, :Ls, "command/ls",
|
168
179
|
[:ls, NO_OVERRIDE],
|
169
180
|
],
|
170
181
|
|
171
182
|
[
|
172
|
-
:irb_measure, :Measure, "
|
183
|
+
:irb_measure, :Measure, "command/measure",
|
173
184
|
[:measure, NO_OVERRIDE],
|
174
185
|
],
|
175
186
|
|
176
187
|
[
|
177
|
-
:irb_show_source, :ShowSource, "
|
188
|
+
:irb_show_source, :ShowSource, "command/show_source",
|
178
189
|
[:show_source, NO_OVERRIDE],
|
179
190
|
],
|
180
|
-
|
181
191
|
[
|
182
|
-
:irb_whereami, :Whereami, "
|
192
|
+
:irb_whereami, :Whereami, "command/whereami",
|
183
193
|
[:whereami, NO_OVERRIDE],
|
184
194
|
],
|
185
195
|
[
|
186
|
-
:
|
187
|
-
[:show_cmds, NO_OVERRIDE],
|
188
|
-
],
|
189
|
-
|
190
|
-
[
|
191
|
-
:irb_history, :History, "cmd/history",
|
196
|
+
:irb_history, :History, "command/history",
|
192
197
|
[:history, NO_OVERRIDE],
|
193
198
|
[:hist, NO_OVERRIDE],
|
194
199
|
]
|
@@ -205,11 +210,11 @@ module IRB # :nodoc:
|
|
205
210
|
end
|
206
211
|
|
207
212
|
@EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
|
208
|
-
if !defined?(
|
213
|
+
if !defined?(Command) || !Command.const_defined?(cmd_class, false)
|
209
214
|
require_relative load_file
|
210
215
|
end
|
211
216
|
|
212
|
-
klass =
|
217
|
+
klass = Command.const_get(cmd_class, false)
|
213
218
|
aliases = aliases.map { |a| a.first }
|
214
219
|
|
215
220
|
if additional_aliases = user_aliases[cmd_name]
|
@@ -229,10 +234,10 @@ module IRB # :nodoc:
|
|
229
234
|
@EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
|
230
235
|
next if cmd_name != command && aliases.all? { |alias_name, _| alias_name != command }
|
231
236
|
|
232
|
-
if !defined?(
|
237
|
+
if !defined?(Command) || !Command.const_defined?(cmd_class, false)
|
233
238
|
require_relative load_file
|
234
239
|
end
|
235
|
-
return
|
240
|
+
return Command.const_get(cmd_class, false)
|
236
241
|
end
|
237
242
|
nil
|
238
243
|
end
|
@@ -262,7 +267,7 @@ module IRB # :nodoc:
|
|
262
267
|
line = __LINE__; eval %[
|
263
268
|
def #{cmd_name}(*opts, **kwargs, &b)
|
264
269
|
Kernel.require_relative "#{load_file}"
|
265
|
-
::IRB::
|
270
|
+
::IRB::Command::#{cmd_class}.execute(irb_context, *opts, **kwargs, &b)
|
266
271
|
end
|
267
272
|
], nil, __FILE__, line
|
268
273
|
|
@@ -310,44 +315,4 @@ module IRB # :nodoc:
|
|
310
315
|
|
311
316
|
install_extend_commands
|
312
317
|
end
|
313
|
-
|
314
|
-
# Extends methods for the Context module
|
315
|
-
module ContextExtender
|
316
|
-
CE = ContextExtender # :nodoc:
|
317
|
-
|
318
|
-
@EXTEND_COMMANDS = [
|
319
|
-
[:eval_history=, "ext/eval_history.rb"],
|
320
|
-
[:use_loader=, "ext/use-loader.rb"],
|
321
|
-
]
|
322
|
-
|
323
|
-
# Installs the default context extensions as irb commands:
|
324
|
-
#
|
325
|
-
# Context#eval_history=:: +irb/ext/history.rb+
|
326
|
-
# Context#use_tracer=:: +irb/ext/tracer.rb+
|
327
|
-
# Context#use_loader=:: +irb/ext/use-loader.rb+
|
328
|
-
def self.install_extend_commands
|
329
|
-
for args in @EXTEND_COMMANDS
|
330
|
-
def_extend_command(*args)
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
# Evaluate the given +command+ from the given +load_file+ on the Context
|
335
|
-
# module.
|
336
|
-
#
|
337
|
-
# Will also define any given +aliases+ for the method.
|
338
|
-
def self.def_extend_command(cmd_name, load_file, *aliases)
|
339
|
-
line = __LINE__; Context.module_eval %[
|
340
|
-
def #{cmd_name}(*opts, &b)
|
341
|
-
Context.module_eval {remove_method(:#{cmd_name})}
|
342
|
-
require_relative "#{load_file}"
|
343
|
-
__send__ :#{cmd_name}, *opts, &b
|
344
|
-
end
|
345
|
-
for ali in aliases
|
346
|
-
alias_method ali, cmd_name
|
347
|
-
end
|
348
|
-
], __FILE__, line
|
349
|
-
end
|
350
|
-
|
351
|
-
CE.install_extend_commands
|
352
|
-
end
|
353
318
|
end
|
data/lib/irb/completion.rb
CHANGED
data/lib/irb/context.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/context.rb - irb context
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -22,10 +22,11 @@ module IRB
|
|
22
22
|
# +other+:: uses this as InputMethod
|
23
23
|
def initialize(irb, workspace = nil, input_method = nil)
|
24
24
|
@irb = irb
|
25
|
+
@workspace_stack = []
|
25
26
|
if workspace
|
26
|
-
@
|
27
|
+
@workspace_stack << workspace
|
27
28
|
else
|
28
|
-
@
|
29
|
+
@workspace_stack << WorkSpace.new
|
29
30
|
end
|
30
31
|
@thread = Thread.current
|
31
32
|
|
@@ -77,7 +78,7 @@ module IRB
|
|
77
78
|
else
|
78
79
|
@irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
|
79
80
|
end
|
80
|
-
|
81
|
+
self.irb_path = "(" + @irb_name + ")"
|
81
82
|
|
82
83
|
case input_method
|
83
84
|
when nil
|
@@ -121,11 +122,11 @@ module IRB
|
|
121
122
|
when '-'
|
122
123
|
@io = FileInputMethod.new($stdin)
|
123
124
|
@irb_name = '-'
|
124
|
-
|
125
|
+
self.irb_path = '-'
|
125
126
|
when String
|
126
127
|
@io = FileInputMethod.new(input_method)
|
127
128
|
@irb_name = File.basename(input_method)
|
128
|
-
|
129
|
+
self.irb_path = input_method
|
129
130
|
else
|
130
131
|
@io = input_method
|
131
132
|
end
|
@@ -166,6 +167,18 @@ module IRB
|
|
166
167
|
IRB.conf[:USE_TRACER] = val
|
167
168
|
end
|
168
169
|
|
170
|
+
def eval_history=(val)
|
171
|
+
self.class.remove_method(__method__)
|
172
|
+
require_relative "ext/eval_history"
|
173
|
+
__send__(__method__, val)
|
174
|
+
end
|
175
|
+
|
176
|
+
def use_loader=(val)
|
177
|
+
self.class.remove_method(__method__)
|
178
|
+
require_relative "ext/use-loader"
|
179
|
+
__send__(__method__, val)
|
180
|
+
end
|
181
|
+
|
169
182
|
private def build_completor
|
170
183
|
completor_type = IRB.conf[:COMPLETOR]
|
171
184
|
case completor_type
|
@@ -217,15 +230,24 @@ module IRB
|
|
217
230
|
IRB.conf[:HISTORY_FILE] = hist
|
218
231
|
end
|
219
232
|
|
233
|
+
# Workspace in the current context.
|
234
|
+
def workspace
|
235
|
+
@workspace_stack.last
|
236
|
+
end
|
237
|
+
|
238
|
+
# Replace the current workspace with the given +workspace+.
|
239
|
+
def replace_workspace(workspace)
|
240
|
+
@workspace_stack.pop
|
241
|
+
@workspace_stack.push(workspace)
|
242
|
+
end
|
243
|
+
|
220
244
|
# The top-level workspace, see WorkSpace#main
|
221
245
|
def main
|
222
|
-
|
246
|
+
workspace.main
|
223
247
|
end
|
224
248
|
|
225
249
|
# The toplevel workspace, see #home_workspace
|
226
250
|
attr_reader :workspace_home
|
227
|
-
# WorkSpace in the current context.
|
228
|
-
attr_accessor :workspace
|
229
251
|
# The current thread in this context.
|
230
252
|
attr_reader :thread
|
231
253
|
# The current input method.
|
@@ -246,9 +268,27 @@ module IRB
|
|
246
268
|
# Can be either name from <code>IRB.conf[:IRB_NAME]</code>, or the number of
|
247
269
|
# the current job set by JobManager, such as <code>irb#2</code>
|
248
270
|
attr_accessor :irb_name
|
249
|
-
|
250
|
-
#
|
251
|
-
|
271
|
+
|
272
|
+
# Can be one of the following:
|
273
|
+
# - the #irb_name surrounded by parenthesis
|
274
|
+
# - the +input_method+ passed to Context.new
|
275
|
+
# - the file path of the current IRB context in a binding.irb session
|
276
|
+
attr_reader :irb_path
|
277
|
+
|
278
|
+
# Sets @irb_path to the given +path+ as well as @eval_path
|
279
|
+
# @eval_path is used for evaluating code in the context of IRB session
|
280
|
+
# It's the same as irb_path, but with the IRB name postfix
|
281
|
+
# This makes sure users can distinguish the methods defined in the IRB session
|
282
|
+
# from the methods defined in the current file's context, especially with binding.irb
|
283
|
+
def irb_path=(path)
|
284
|
+
@irb_path = path
|
285
|
+
|
286
|
+
if File.exist?(path)
|
287
|
+
@eval_path = "#{path}(#{IRB.conf[:IRB_NAME]})"
|
288
|
+
else
|
289
|
+
@eval_path = path
|
290
|
+
end
|
291
|
+
end
|
252
292
|
|
253
293
|
# Whether multiline editor mode is enabled or not.
|
254
294
|
#
|
@@ -449,9 +489,7 @@ module IRB
|
|
449
489
|
# StdioInputMethod or RelineInputMethod or ReadlineInputMethod, see #io
|
450
490
|
# for more information.
|
451
491
|
def prompting?
|
452
|
-
verbose? ||
|
453
|
-
@io.kind_of?(RelineInputMethod) ||
|
454
|
-
(defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
|
492
|
+
verbose? || @io.prompting?
|
455
493
|
end
|
456
494
|
|
457
495
|
# The return value of the last statement evaluated.
|
@@ -461,7 +499,7 @@ module IRB
|
|
461
499
|
# to #last_value.
|
462
500
|
def set_last_value(value)
|
463
501
|
@last_value = value
|
464
|
-
|
502
|
+
workspace.local_variable_set :_, value
|
465
503
|
end
|
466
504
|
|
467
505
|
# Sets the +mode+ of the prompt in this context.
|
@@ -557,7 +595,7 @@ module IRB
|
|
557
595
|
|
558
596
|
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
|
559
597
|
last_proc = proc do
|
560
|
-
result =
|
598
|
+
result = workspace.evaluate(line, @eval_path, line_no)
|
561
599
|
end
|
562
600
|
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item|
|
563
601
|
_name, callback, arg = item
|
@@ -568,7 +606,7 @@ module IRB
|
|
568
606
|
end
|
569
607
|
end.call
|
570
608
|
else
|
571
|
-
result =
|
609
|
+
result = workspace.evaluate(line, @eval_path, line_no)
|
572
610
|
end
|
573
611
|
|
574
612
|
set_last_value(result)
|
data/lib/irb/ext/change-ws.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# irb/ext/cb.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -12,7 +12,7 @@ module IRB # :nodoc:
|
|
12
12
|
if defined? @home_workspace
|
13
13
|
@home_workspace
|
14
14
|
else
|
15
|
-
@home_workspace =
|
15
|
+
@home_workspace = workspace
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -25,11 +25,11 @@ module IRB # :nodoc:
|
|
25
25
|
# See IRB::WorkSpace.new for more information.
|
26
26
|
def change_workspace(*_main)
|
27
27
|
if _main.empty?
|
28
|
-
|
28
|
+
replace_workspace(home_workspace)
|
29
29
|
return main
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
replace_workspace(WorkSpace.new(_main[0]))
|
33
33
|
|
34
34
|
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
35
35
|
main.extend ExtendCommandBundle
|
data/lib/irb/ext/eval_history.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# history.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -18,7 +18,7 @@ module IRB # :nodoc:
|
|
18
18
|
|
19
19
|
if defined?(@eval_history) && @eval_history
|
20
20
|
@eval_history_values.push @line_no, @last_value
|
21
|
-
|
21
|
+
workspace.evaluate "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
|
22
22
|
end
|
23
23
|
|
24
24
|
@last_value
|
@@ -49,7 +49,7 @@ module IRB # :nodoc:
|
|
49
49
|
else
|
50
50
|
@eval_history_values = EvalHistory.new(no)
|
51
51
|
IRB.conf[:__TMP__EHV__] = @eval_history_values
|
52
|
-
|
52
|
+
workspace.evaluate("__ = IRB.conf[:__TMP__EHV__]")
|
53
53
|
IRB.conf.delete(:__TMP_EHV__)
|
54
54
|
end
|
55
55
|
else
|
data/lib/irb/ext/loader.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# loader.rb -
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
@@ -98,13 +98,13 @@ module IRB # :nodoc:
|
|
98
98
|
|
99
99
|
def old # :nodoc:
|
100
100
|
back_io = @io
|
101
|
-
back_path =
|
101
|
+
back_path = irb_path
|
102
102
|
back_name = @irb_name
|
103
103
|
back_scanner = @irb.scanner
|
104
104
|
begin
|
105
105
|
@io = FileInputMethod.new(path)
|
106
106
|
@irb_name = File.basename(path)
|
107
|
-
|
107
|
+
self.irb_path = path
|
108
108
|
@irb.signal_status(:IN_LOAD) do
|
109
109
|
if back_io.kind_of?(FileInputMethod)
|
110
110
|
@irb.eval_input
|
@@ -119,7 +119,7 @@ module IRB # :nodoc:
|
|
119
119
|
ensure
|
120
120
|
@io = back_io
|
121
121
|
@irb_name = back_name
|
122
|
-
|
122
|
+
self.irb_path = back_path
|
123
123
|
@irb.scanner = back_scanner
|
124
124
|
end
|
125
125
|
end
|
data/lib/irb/ext/multi-irb.rb
CHANGED