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/command/pushws.rb
CHANGED
@@ -14,7 +14,7 @@ module IRB
|
|
14
14
|
category "Workspace"
|
15
15
|
description "Show workspaces."
|
16
16
|
|
17
|
-
def execute(
|
17
|
+
def execute(_arg)
|
18
18
|
inspection_resuls = irb_context.instance_variable_get(:@workspace_stack).map do |ws|
|
19
19
|
truncated_inspect(ws.main)
|
20
20
|
end
|
@@ -39,8 +39,13 @@ module IRB
|
|
39
39
|
category "Workspace"
|
40
40
|
description "Push an object to the workspace stack."
|
41
41
|
|
42
|
-
def execute(
|
43
|
-
|
42
|
+
def execute(arg)
|
43
|
+
if arg.empty?
|
44
|
+
irb_context.push_workspace
|
45
|
+
else
|
46
|
+
obj = eval(arg, irb_context.workspace.binding)
|
47
|
+
irb_context.push_workspace(obj)
|
48
|
+
end
|
44
49
|
super
|
45
50
|
end
|
46
51
|
end
|
@@ -49,8 +54,8 @@ module IRB
|
|
49
54
|
category "Workspace"
|
50
55
|
description "Pop a workspace from the workspace stack."
|
51
56
|
|
52
|
-
def execute(
|
53
|
-
irb_context.pop_workspace
|
57
|
+
def execute(_arg)
|
58
|
+
irb_context.pop_workspace
|
54
59
|
super
|
55
60
|
end
|
56
61
|
end
|
data/lib/irb/command/show_doc.rb
CHANGED
@@ -3,16 +3,7 @@
|
|
3
3
|
module IRB
|
4
4
|
module Command
|
5
5
|
class ShowDoc < Base
|
6
|
-
|
7
|
-
def transform_args(args)
|
8
|
-
# Return a string literal as is for backward compatibility
|
9
|
-
if args.empty? || string_literal?(args)
|
10
|
-
args
|
11
|
-
else # Otherwise, consider the input as a String for convenience
|
12
|
-
args.strip.dump
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
6
|
+
include RubyArgsExtractor
|
16
7
|
|
17
8
|
category "Context"
|
18
9
|
description "Look up documentation with RI."
|
@@ -31,7 +22,9 @@ module IRB
|
|
31
22
|
|
32
23
|
HELP_MESSAGE
|
33
24
|
|
34
|
-
def execute(
|
25
|
+
def execute(arg)
|
26
|
+
# Accept string literal for backward compatibility
|
27
|
+
name = unwrap_string_literal(arg)
|
35
28
|
require 'rdoc/ri/driver'
|
36
29
|
|
37
30
|
unless ShowDoc.const_defined?(:Ri)
|
@@ -39,15 +32,13 @@ module IRB
|
|
39
32
|
ShowDoc.const_set(:Ri, RDoc::RI::Driver.new(opts))
|
40
33
|
end
|
41
34
|
|
42
|
-
if
|
35
|
+
if name.nil?
|
43
36
|
Ri.interactive
|
44
37
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
puts $!.message
|
50
|
-
end
|
38
|
+
begin
|
39
|
+
Ri.display_name(name)
|
40
|
+
rescue RDoc::RI::Error
|
41
|
+
puts $!.message
|
51
42
|
end
|
52
43
|
end
|
53
44
|
|
@@ -7,6 +7,8 @@ require_relative "../color"
|
|
7
7
|
module IRB
|
8
8
|
module Command
|
9
9
|
class ShowSource < Base
|
10
|
+
include RubyArgsExtractor
|
11
|
+
|
10
12
|
category "Context"
|
11
13
|
description "Show the source code of a given method, class/module, or constant."
|
12
14
|
|
@@ -24,18 +26,9 @@ module IRB
|
|
24
26
|
show_source Foo::BAR
|
25
27
|
HELP_MESSAGE
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if args.empty? || string_literal?(args)
|
31
|
-
args
|
32
|
-
else # Otherwise, consider the input as a String for convenience
|
33
|
-
args.strip.dump
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def execute(str = nil)
|
29
|
+
def execute(arg)
|
30
|
+
# Accept string literal for backward compatibility
|
31
|
+
str = unwrap_string_literal(arg)
|
39
32
|
unless str.is_a?(String)
|
40
33
|
puts "Error: Expected a string but got #{str.inspect}"
|
41
34
|
return
|
data/lib/irb/command/step.rb
CHANGED
data/lib/irb/command/subirb.rb
CHANGED
@@ -9,9 +9,7 @@ module IRB
|
|
9
9
|
|
10
10
|
module Command
|
11
11
|
class MultiIRBCommand < Base
|
12
|
-
|
13
|
-
extend_irb_context
|
14
|
-
end
|
12
|
+
include RubyArgsExtractor
|
15
13
|
|
16
14
|
private
|
17
15
|
|
@@ -36,7 +34,12 @@ module IRB
|
|
36
34
|
category "Multi-irb (DEPRECATED)"
|
37
35
|
description "Start a child IRB."
|
38
36
|
|
39
|
-
def execute(
|
37
|
+
def execute(arg)
|
38
|
+
args, kwargs = ruby_args(arg)
|
39
|
+
execute_internal(*args, **kwargs)
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute_internal(*obj)
|
40
43
|
print_deprecated_warning
|
41
44
|
|
42
45
|
if irb_context.with_debugger
|
@@ -44,8 +47,9 @@ module IRB
|
|
44
47
|
return
|
45
48
|
end
|
46
49
|
|
47
|
-
|
50
|
+
extend_irb_context
|
48
51
|
IRB.irb(nil, *obj)
|
52
|
+
puts IRB.JobManager.inspect
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
@@ -53,7 +57,7 @@ module IRB
|
|
53
57
|
category "Multi-irb (DEPRECATED)"
|
54
58
|
description "List of current sessions."
|
55
59
|
|
56
|
-
def execute
|
60
|
+
def execute(_arg)
|
57
61
|
print_deprecated_warning
|
58
62
|
|
59
63
|
if irb_context.with_debugger
|
@@ -61,8 +65,8 @@ module IRB
|
|
61
65
|
return
|
62
66
|
end
|
63
67
|
|
64
|
-
|
65
|
-
IRB.JobManager
|
68
|
+
extend_irb_context
|
69
|
+
puts IRB.JobManager.inspect
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
@@ -70,7 +74,12 @@ module IRB
|
|
70
74
|
category "Multi-irb (DEPRECATED)"
|
71
75
|
description "Switches to the session of the given number."
|
72
76
|
|
73
|
-
def execute(
|
77
|
+
def execute(arg)
|
78
|
+
args, kwargs = ruby_args(arg)
|
79
|
+
execute_internal(*args, **kwargs)
|
80
|
+
end
|
81
|
+
|
82
|
+
def execute_internal(key = nil)
|
74
83
|
print_deprecated_warning
|
75
84
|
|
76
85
|
if irb_context.with_debugger
|
@@ -78,10 +87,11 @@ module IRB
|
|
78
87
|
return
|
79
88
|
end
|
80
89
|
|
81
|
-
|
90
|
+
extend_irb_context
|
82
91
|
|
83
92
|
raise CommandArgumentError.new("Please specify the id of target IRB job (listed in the `jobs` command).") unless key
|
84
93
|
IRB.JobManager.switch(key)
|
94
|
+
puts IRB.JobManager.inspect
|
85
95
|
end
|
86
96
|
end
|
87
97
|
|
@@ -89,7 +99,12 @@ module IRB
|
|
89
99
|
category "Multi-irb (DEPRECATED)"
|
90
100
|
description "Kills the session with the given number."
|
91
101
|
|
92
|
-
def execute(
|
102
|
+
def execute(arg)
|
103
|
+
args, kwargs = ruby_args(arg)
|
104
|
+
execute_internal(*args, **kwargs)
|
105
|
+
end
|
106
|
+
|
107
|
+
def execute_internal(*keys)
|
93
108
|
print_deprecated_warning
|
94
109
|
|
95
110
|
if irb_context.with_debugger
|
@@ -97,8 +112,9 @@ module IRB
|
|
97
112
|
return
|
98
113
|
end
|
99
114
|
|
100
|
-
|
115
|
+
extend_irb_context
|
101
116
|
IRB.JobManager.kill(*keys)
|
117
|
+
puts IRB.JobManager.inspect
|
102
118
|
end
|
103
119
|
end
|
104
120
|
end
|
data/lib/irb/command/whereami.rb
CHANGED
data/lib/irb/command.rb
CHANGED
@@ -7,312 +7,17 @@
|
|
7
7
|
require_relative "command/base"
|
8
8
|
|
9
9
|
module IRB # :nodoc:
|
10
|
-
module Command
|
11
|
-
|
10
|
+
module Command
|
11
|
+
@commands = {}
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
EXCB = ExtendCommandBundle # :nodoc:
|
13
|
+
class << self
|
14
|
+
attr_reader :commands
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# See #install_alias_method.
|
22
|
-
OVERRIDE_ALL = 0x02
|
23
|
-
|
24
|
-
# Displays current configuration.
|
25
|
-
#
|
26
|
-
# Modifying the configuration is achieved by sending a message to IRB.conf.
|
27
|
-
def irb_context
|
28
|
-
IRB.CurrentContext
|
29
|
-
end
|
30
|
-
|
31
|
-
@ALIASES = [
|
32
|
-
[:context, :irb_context, NO_OVERRIDE],
|
33
|
-
[:conf, :irb_context, NO_OVERRIDE],
|
34
|
-
]
|
35
|
-
|
36
|
-
|
37
|
-
@EXTEND_COMMANDS = [
|
38
|
-
[
|
39
|
-
:irb_exit, :Exit, "command/exit",
|
40
|
-
[:exit, OVERRIDE_PRIVATE_ONLY],
|
41
|
-
[:quit, OVERRIDE_PRIVATE_ONLY],
|
42
|
-
[:irb_quit, OVERRIDE_PRIVATE_ONLY],
|
43
|
-
],
|
44
|
-
[
|
45
|
-
:irb_exit!, :ForceExit, "command/force_exit",
|
46
|
-
[:exit!, OVERRIDE_PRIVATE_ONLY],
|
47
|
-
],
|
48
|
-
|
49
|
-
[
|
50
|
-
:irb_current_working_workspace, :CurrentWorkingWorkspace, "command/chws",
|
51
|
-
[:cwws, NO_OVERRIDE],
|
52
|
-
[:pwws, NO_OVERRIDE],
|
53
|
-
[:irb_print_working_workspace, OVERRIDE_ALL],
|
54
|
-
[:irb_cwws, OVERRIDE_ALL],
|
55
|
-
[:irb_pwws, OVERRIDE_ALL],
|
56
|
-
[:irb_current_working_binding, OVERRIDE_ALL],
|
57
|
-
[:irb_print_working_binding, OVERRIDE_ALL],
|
58
|
-
[:irb_cwb, OVERRIDE_ALL],
|
59
|
-
[:irb_pwb, OVERRIDE_ALL],
|
60
|
-
],
|
61
|
-
[
|
62
|
-
:irb_change_workspace, :ChangeWorkspace, "command/chws",
|
63
|
-
[:chws, NO_OVERRIDE],
|
64
|
-
[:cws, NO_OVERRIDE],
|
65
|
-
[:irb_chws, OVERRIDE_ALL],
|
66
|
-
[:irb_cws, OVERRIDE_ALL],
|
67
|
-
[:irb_change_binding, OVERRIDE_ALL],
|
68
|
-
[:irb_cb, OVERRIDE_ALL],
|
69
|
-
[:cb, NO_OVERRIDE],
|
70
|
-
],
|
71
|
-
|
72
|
-
[
|
73
|
-
:irb_workspaces, :Workspaces, "command/pushws",
|
74
|
-
[:workspaces, NO_OVERRIDE],
|
75
|
-
[:irb_bindings, OVERRIDE_ALL],
|
76
|
-
[:bindings, NO_OVERRIDE],
|
77
|
-
],
|
78
|
-
[
|
79
|
-
:irb_push_workspace, :PushWorkspace, "command/pushws",
|
80
|
-
[:pushws, NO_OVERRIDE],
|
81
|
-
[:irb_pushws, OVERRIDE_ALL],
|
82
|
-
[:irb_push_binding, OVERRIDE_ALL],
|
83
|
-
[:irb_pushb, OVERRIDE_ALL],
|
84
|
-
[:pushb, NO_OVERRIDE],
|
85
|
-
],
|
86
|
-
[
|
87
|
-
:irb_pop_workspace, :PopWorkspace, "command/pushws",
|
88
|
-
[:popws, NO_OVERRIDE],
|
89
|
-
[:irb_popws, OVERRIDE_ALL],
|
90
|
-
[:irb_pop_binding, OVERRIDE_ALL],
|
91
|
-
[:irb_popb, OVERRIDE_ALL],
|
92
|
-
[:popb, NO_OVERRIDE],
|
93
|
-
],
|
94
|
-
|
95
|
-
[
|
96
|
-
:irb_load, :Load, "command/load"],
|
97
|
-
[
|
98
|
-
:irb_require, :Require, "command/load"],
|
99
|
-
[
|
100
|
-
:irb_source, :Source, "command/load",
|
101
|
-
[:source, NO_OVERRIDE],
|
102
|
-
],
|
103
|
-
|
104
|
-
[
|
105
|
-
:irb, :IrbCommand, "command/subirb"],
|
106
|
-
[
|
107
|
-
:irb_jobs, :Jobs, "command/subirb",
|
108
|
-
[:jobs, NO_OVERRIDE],
|
109
|
-
],
|
110
|
-
[
|
111
|
-
:irb_fg, :Foreground, "command/subirb",
|
112
|
-
[:fg, NO_OVERRIDE],
|
113
|
-
],
|
114
|
-
[
|
115
|
-
:irb_kill, :Kill, "command/subirb",
|
116
|
-
[:kill, OVERRIDE_PRIVATE_ONLY],
|
117
|
-
],
|
118
|
-
|
119
|
-
[
|
120
|
-
:irb_debug, :Debug, "command/debug",
|
121
|
-
[:debug, NO_OVERRIDE],
|
122
|
-
],
|
123
|
-
[
|
124
|
-
:irb_edit, :Edit, "command/edit",
|
125
|
-
[:edit, NO_OVERRIDE],
|
126
|
-
],
|
127
|
-
[
|
128
|
-
:irb_break, :Break, "command/break",
|
129
|
-
],
|
130
|
-
[
|
131
|
-
:irb_catch, :Catch, "command/catch",
|
132
|
-
],
|
133
|
-
[
|
134
|
-
:irb_next, :Next, "command/next"
|
135
|
-
],
|
136
|
-
[
|
137
|
-
:irb_delete, :Delete, "command/delete",
|
138
|
-
[:delete, NO_OVERRIDE],
|
139
|
-
],
|
140
|
-
[
|
141
|
-
:irb_step, :Step, "command/step",
|
142
|
-
[:step, NO_OVERRIDE],
|
143
|
-
],
|
144
|
-
[
|
145
|
-
:irb_continue, :Continue, "command/continue",
|
146
|
-
[:continue, NO_OVERRIDE],
|
147
|
-
],
|
148
|
-
[
|
149
|
-
:irb_finish, :Finish, "command/finish",
|
150
|
-
[:finish, NO_OVERRIDE],
|
151
|
-
],
|
152
|
-
[
|
153
|
-
:irb_backtrace, :Backtrace, "command/backtrace",
|
154
|
-
[:backtrace, NO_OVERRIDE],
|
155
|
-
[:bt, NO_OVERRIDE],
|
156
|
-
],
|
157
|
-
[
|
158
|
-
:irb_debug_info, :Info, "command/info",
|
159
|
-
[:info, NO_OVERRIDE],
|
160
|
-
],
|
161
|
-
|
162
|
-
[
|
163
|
-
:irb_help, :Help, "command/help",
|
164
|
-
[:help, NO_OVERRIDE],
|
165
|
-
[:show_cmds, NO_OVERRIDE],
|
166
|
-
],
|
167
|
-
|
168
|
-
[
|
169
|
-
:irb_show_doc, :ShowDoc, "command/show_doc",
|
170
|
-
[:show_doc, NO_OVERRIDE],
|
171
|
-
],
|
172
|
-
|
173
|
-
[
|
174
|
-
:irb_info, :IrbInfo, "command/irb_info"
|
175
|
-
],
|
176
|
-
|
177
|
-
[
|
178
|
-
:irb_ls, :Ls, "command/ls",
|
179
|
-
[:ls, NO_OVERRIDE],
|
180
|
-
],
|
181
|
-
|
182
|
-
[
|
183
|
-
:irb_measure, :Measure, "command/measure",
|
184
|
-
[:measure, NO_OVERRIDE],
|
185
|
-
],
|
186
|
-
|
187
|
-
[
|
188
|
-
:irb_show_source, :ShowSource, "command/show_source",
|
189
|
-
[:show_source, NO_OVERRIDE],
|
190
|
-
],
|
191
|
-
[
|
192
|
-
:irb_whereami, :Whereami, "command/whereami",
|
193
|
-
[:whereami, NO_OVERRIDE],
|
194
|
-
],
|
195
|
-
[
|
196
|
-
:irb_history, :History, "command/history",
|
197
|
-
[:history, NO_OVERRIDE],
|
198
|
-
[:hist, NO_OVERRIDE],
|
199
|
-
]
|
200
|
-
]
|
201
|
-
|
202
|
-
|
203
|
-
@@commands = []
|
204
|
-
|
205
|
-
def self.all_commands_info
|
206
|
-
return @@commands unless @@commands.empty?
|
207
|
-
user_aliases = IRB.CurrentContext.command_aliases.each_with_object({}) do |(alias_name, target), result|
|
208
|
-
result[target] ||= []
|
209
|
-
result[target] << alias_name
|
210
|
-
end
|
211
|
-
|
212
|
-
@EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
|
213
|
-
if !defined?(Command) || !Command.const_defined?(cmd_class, false)
|
214
|
-
require_relative load_file
|
215
|
-
end
|
216
|
-
|
217
|
-
klass = Command.const_get(cmd_class, false)
|
218
|
-
aliases = aliases.map { |a| a.first }
|
219
|
-
|
220
|
-
if additional_aliases = user_aliases[cmd_name]
|
221
|
-
aliases += additional_aliases
|
222
|
-
end
|
223
|
-
|
224
|
-
display_name = aliases.shift || cmd_name
|
225
|
-
@@commands << { display_name: display_name, description: klass.description, category: klass.category }
|
226
|
-
end
|
227
|
-
|
228
|
-
@@commands
|
229
|
-
end
|
230
|
-
|
231
|
-
# Convert a command name to its implementation class if such command exists
|
232
|
-
def self.load_command(command)
|
233
|
-
command = command.to_sym
|
234
|
-
@EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
|
235
|
-
next if cmd_name != command && aliases.all? { |alias_name, _| alias_name != command }
|
236
|
-
|
237
|
-
if !defined?(Command) || !Command.const_defined?(cmd_class, false)
|
238
|
-
require_relative load_file
|
239
|
-
end
|
240
|
-
return Command.const_get(cmd_class, false)
|
241
|
-
end
|
242
|
-
nil
|
243
|
-
end
|
244
|
-
|
245
|
-
# Installs the default irb commands.
|
246
|
-
def self.install_extend_commands
|
247
|
-
for args in @EXTEND_COMMANDS
|
248
|
-
def_extend_command(*args)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
# Evaluate the given +cmd_name+ on the given +cmd_class+ Class.
|
253
|
-
#
|
254
|
-
# Will also define any given +aliases+ for the method.
|
255
|
-
#
|
256
|
-
# The optional +load_file+ parameter will be required within the method
|
257
|
-
# definition.
|
258
|
-
def self.def_extend_command(cmd_name, cmd_class, load_file, *aliases)
|
259
|
-
case cmd_class
|
260
|
-
when Symbol
|
261
|
-
cmd_class = cmd_class.id2name
|
262
|
-
when String
|
263
|
-
when Class
|
264
|
-
cmd_class = cmd_class.name
|
265
|
-
end
|
266
|
-
|
267
|
-
line = __LINE__; eval %[
|
268
|
-
def #{cmd_name}(*opts, **kwargs, &b)
|
269
|
-
Kernel.require_relative "#{load_file}"
|
270
|
-
::IRB::Command::#{cmd_class}.execute(irb_context, *opts, **kwargs, &b)
|
271
|
-
end
|
272
|
-
], nil, __FILE__, line
|
273
|
-
|
274
|
-
for ali, flag in aliases
|
275
|
-
@ALIASES.push [ali, cmd_name, flag]
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
# Installs alias methods for the default irb commands, see
|
280
|
-
# ::install_extend_commands.
|
281
|
-
def install_alias_method(to, from, override = NO_OVERRIDE)
|
282
|
-
to = to.id2name unless to.kind_of?(String)
|
283
|
-
from = from.id2name unless from.kind_of?(String)
|
284
|
-
|
285
|
-
if override == OVERRIDE_ALL or
|
286
|
-
(override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
|
287
|
-
(override == NO_OVERRIDE) && !respond_to?(to, true)
|
288
|
-
target = self
|
289
|
-
(class << self; self; end).instance_eval{
|
290
|
-
if target.respond_to?(to, true) &&
|
291
|
-
!target.respond_to?(EXCB.irb_original_method_name(to), true)
|
292
|
-
alias_method(EXCB.irb_original_method_name(to), to)
|
293
|
-
end
|
294
|
-
alias_method to, from
|
295
|
-
}
|
296
|
-
else
|
297
|
-
Kernel.warn "irb: warn: can't alias #{to} from #{from}.\n"
|
16
|
+
# Registers a command with the given name.
|
17
|
+
# Aliasing is intentionally not supported at the moment.
|
18
|
+
def register(name, command_class)
|
19
|
+
@commands[name.to_sym] = [command_class, []]
|
298
20
|
end
|
299
21
|
end
|
300
|
-
|
301
|
-
def self.irb_original_method_name(method_name) # :nodoc:
|
302
|
-
"irb_" + method_name + "_org"
|
303
|
-
end
|
304
|
-
|
305
|
-
# Installs alias methods for the default irb commands on the given object
|
306
|
-
# using #install_alias_method.
|
307
|
-
def self.extend_object(obj)
|
308
|
-
unless (class << obj; ancestors; end).include?(EXCB)
|
309
|
-
super
|
310
|
-
for ali, com, flg in @ALIASES
|
311
|
-
obj.install_alias_method(ali, com, flg)
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
install_extend_commands
|
317
22
|
end
|
318
23
|
end
|
data/lib/irb/completion.rb
CHANGED
@@ -86,6 +86,14 @@ module IRB
|
|
86
86
|
)
|
87
87
|
end
|
88
88
|
|
89
|
+
def command_completions(preposing, target)
|
90
|
+
if preposing.empty? && !target.empty?
|
91
|
+
IRB::Command.command_names.select { _1.start_with?(target) }
|
92
|
+
else
|
93
|
+
[]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
89
97
|
def retrieve_files_to_require_relative_from_current_dir
|
90
98
|
@files_from_current_dir ||= Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: '.').map { |path|
|
91
99
|
path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
|
@@ -103,9 +111,11 @@ module IRB
|
|
103
111
|
end
|
104
112
|
|
105
113
|
def completion_candidates(preposing, target, _postposing, bind:)
|
114
|
+
commands = command_completions(preposing, target)
|
106
115
|
result = ReplTypeCompletor.analyze(preposing + target, binding: bind, filename: @context.irb_path)
|
107
|
-
return
|
108
|
-
|
116
|
+
return commands unless result
|
117
|
+
|
118
|
+
commands | result.completion_candidates.map { target + _1 }
|
109
119
|
end
|
110
120
|
|
111
121
|
def doc_namespace(preposing, matched, _postposing, bind:)
|
@@ -181,7 +191,8 @@ module IRB
|
|
181
191
|
result = complete_require_path(target, preposing, postposing)
|
182
192
|
return result if result
|
183
193
|
end
|
184
|
-
|
194
|
+
commands = command_completions(preposing || '', target)
|
195
|
+
commands | retrieve_completion_data(target, bind: bind, doc_namespace: false).compact.map{ |i| i.encode(Encoding.default_external) }
|
185
196
|
end
|
186
197
|
|
187
198
|
def doc_namespace(_preposing, matched, _postposing, bind:)
|
@@ -388,7 +399,7 @@ module IRB
|
|
388
399
|
|
389
400
|
if doc_namespace
|
390
401
|
rec_class = rec.is_a?(Module) ? rec : rec.class
|
391
|
-
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
|
402
|
+
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}" rescue nil
|
392
403
|
else
|
393
404
|
select_message(receiver, message, candidates, sep)
|
394
405
|
end
|
@@ -418,7 +429,7 @@ module IRB
|
|
418
429
|
vars = (bind.local_variables | bind.eval_instance_variables).collect{|m| m.to_s}
|
419
430
|
perfect_match_var = vars.find{|m| m.to_s == input}
|
420
431
|
if perfect_match_var
|
421
|
-
eval("#{perfect_match_var}.class.name", bind)
|
432
|
+
eval("#{perfect_match_var}.class.name", bind) rescue nil
|
422
433
|
else
|
423
434
|
candidates = (bind.eval_methods | bind.eval_private_methods | bind.local_variables | bind.eval_instance_variables | bind.eval_class_constants).collect{|m| m.to_s}
|
424
435
|
candidates |= ReservedWords
|
data/lib/irb/context.rb
CHANGED
@@ -585,31 +585,45 @@ module IRB
|
|
585
585
|
@inspect_mode
|
586
586
|
end
|
587
587
|
|
588
|
-
def evaluate(
|
588
|
+
def evaluate(statement, line_no) # :nodoc:
|
589
589
|
@line_no = line_no
|
590
|
-
result = nil
|
591
590
|
|
591
|
+
case statement
|
592
|
+
when Statement::EmptyInput
|
593
|
+
return
|
594
|
+
when Statement::Expression
|
595
|
+
result = evaluate_expression(statement.code, line_no)
|
596
|
+
set_last_value(result)
|
597
|
+
when Statement::Command
|
598
|
+
statement.command_class.execute(self, statement.arg)
|
599
|
+
set_last_value(nil)
|
600
|
+
end
|
601
|
+
|
602
|
+
nil
|
603
|
+
end
|
604
|
+
|
605
|
+
def evaluate_expression(code, line_no) # :nodoc:
|
606
|
+
result = nil
|
592
607
|
if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
|
593
608
|
IRB.set_measure_callback
|
594
609
|
end
|
595
610
|
|
596
611
|
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
|
597
612
|
last_proc = proc do
|
598
|
-
result = workspace.evaluate(
|
613
|
+
result = workspace.evaluate(code, @eval_path, line_no)
|
599
614
|
end
|
600
615
|
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item|
|
601
616
|
_name, callback, arg = item
|
602
617
|
proc do
|
603
|
-
callback.(self,
|
618
|
+
callback.(self, code, line_no, arg) do
|
604
619
|
chain.call
|
605
620
|
end
|
606
621
|
end
|
607
622
|
end.call
|
608
623
|
else
|
609
|
-
result = workspace.evaluate(
|
624
|
+
result = workspace.evaluate(code, @eval_path, line_no)
|
610
625
|
end
|
611
|
-
|
612
|
-
set_last_value(result)
|
626
|
+
result
|
613
627
|
end
|
614
628
|
|
615
629
|
def inspect_last_value # :nodoc:
|
@@ -646,17 +660,5 @@ module IRB
|
|
646
660
|
def local_variables # :nodoc:
|
647
661
|
workspace.binding.local_variables
|
648
662
|
end
|
649
|
-
|
650
|
-
# Return true if it's aliased from the argument and it's not an identifier.
|
651
|
-
def symbol_alias?(command)
|
652
|
-
return nil if command.match?(/\A\w+\z/)
|
653
|
-
command_aliases.key?(command.to_sym)
|
654
|
-
end
|
655
|
-
|
656
|
-
# Return true if the command supports transforming args
|
657
|
-
def transform_args?(command)
|
658
|
-
command = command_aliases.fetch(command.to_sym, command)
|
659
|
-
ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args)
|
660
|
-
end
|
661
663
|
end
|
662
664
|
end
|