irb 1.7.1 → 1.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.document +1 -1
  3. data/Gemfile +10 -1
  4. data/README.md +265 -20
  5. data/Rakefile +13 -10
  6. data/doc/irb/irb.rd.ja +1 -3
  7. data/irb.gemspec +2 -1
  8. data/lib/irb/cmd/nop.rb +3 -52
  9. data/lib/irb/color.rb +4 -2
  10. data/lib/irb/command/backtrace.rb +17 -0
  11. data/lib/irb/command/base.rb +62 -0
  12. data/lib/irb/command/break.rb +17 -0
  13. data/lib/irb/command/catch.rb +17 -0
  14. data/lib/irb/command/chws.rb +40 -0
  15. data/lib/irb/command/context.rb +16 -0
  16. data/lib/irb/{cmd → command}/continue.rb +3 -3
  17. data/lib/irb/command/debug.rb +71 -0
  18. data/lib/irb/{cmd → command}/delete.rb +3 -3
  19. data/lib/irb/command/disable_irb.rb +19 -0
  20. data/lib/irb/command/edit.rb +63 -0
  21. data/lib/irb/command/exit.rb +18 -0
  22. data/lib/irb/{cmd → command}/finish.rb +3 -3
  23. data/lib/irb/command/force_exit.rb +18 -0
  24. data/lib/irb/command/help.rb +83 -0
  25. data/lib/irb/command/history.rb +45 -0
  26. data/lib/irb/command/info.rb +17 -0
  27. data/lib/irb/command/internal_helpers.rb +27 -0
  28. data/lib/irb/{cmd → command}/irb_info.rb +7 -7
  29. data/lib/irb/{cmd → command}/load.rb +23 -8
  30. data/lib/irb/{cmd → command}/ls.rb +42 -19
  31. data/lib/irb/{cmd → command}/measure.rb +18 -17
  32. data/lib/irb/{cmd → command}/next.rb +3 -3
  33. data/lib/irb/command/pushws.rb +65 -0
  34. data/lib/irb/command/show_doc.rb +51 -0
  35. data/lib/irb/command/show_source.rb +74 -0
  36. data/lib/irb/{cmd → command}/step.rb +3 -3
  37. data/lib/irb/command/subirb.rb +123 -0
  38. data/lib/irb/{cmd → command}/whereami.rb +3 -5
  39. data/lib/irb/command.rb +23 -0
  40. data/lib/irb/completion.rb +133 -102
  41. data/lib/irb/context.rb +182 -66
  42. data/lib/irb/debug/ui.rb +103 -0
  43. data/lib/irb/{cmd/debug.rb → debug.rb} +53 -59
  44. data/lib/irb/default_commands.rb +265 -0
  45. data/lib/irb/easter-egg.rb +16 -6
  46. data/lib/irb/ext/change-ws.rb +6 -8
  47. data/lib/irb/ext/{history.rb → eval_history.rb} +7 -7
  48. data/lib/irb/ext/loader.rb +4 -4
  49. data/lib/irb/ext/multi-irb.rb +5 -5
  50. data/lib/irb/ext/tracer.rb +12 -51
  51. data/lib/irb/ext/use-loader.rb +6 -8
  52. data/lib/irb/ext/workspaces.rb +10 -34
  53. data/lib/irb/frame.rb +1 -1
  54. data/lib/irb/help.rb +3 -3
  55. data/lib/irb/helper_method/base.rb +16 -0
  56. data/lib/irb/helper_method/conf.rb +11 -0
  57. data/lib/irb/helper_method.rb +29 -0
  58. data/lib/irb/{ext/save-history.rb → history.rb} +20 -58
  59. data/lib/irb/init.rb +154 -58
  60. data/lib/irb/input-method.rb +238 -203
  61. data/lib/irb/inspector.rb +3 -3
  62. data/lib/irb/lc/error.rb +1 -11
  63. data/lib/irb/lc/help-message +4 -0
  64. data/lib/irb/lc/ja/error.rb +1 -11
  65. data/lib/irb/lc/ja/help-message +13 -0
  66. data/lib/irb/locale.rb +2 -2
  67. data/lib/irb/nesting_parser.rb +13 -3
  68. data/lib/irb/notifier.rb +1 -1
  69. data/lib/irb/output-method.rb +2 -8
  70. data/lib/irb/pager.rb +91 -0
  71. data/lib/irb/ruby-lex.rb +391 -471
  72. data/lib/irb/ruby_logo.aa +43 -0
  73. data/lib/irb/source_finder.rb +139 -0
  74. data/lib/irb/statement.rb +80 -0
  75. data/lib/irb/version.rb +3 -3
  76. data/lib/irb/workspace.rb +24 -4
  77. data/lib/irb/ws-for-case-2.rb +1 -1
  78. data/lib/irb/xmp.rb +3 -3
  79. data/lib/irb.rb +1232 -604
  80. data/man/irb.1 +7 -0
  81. metadata +60 -32
  82. data/lib/irb/cmd/backtrace.rb +0 -21
  83. data/lib/irb/cmd/break.rb +0 -21
  84. data/lib/irb/cmd/catch.rb +0 -21
  85. data/lib/irb/cmd/chws.rb +0 -36
  86. data/lib/irb/cmd/edit.rb +0 -61
  87. data/lib/irb/cmd/help.rb +0 -23
  88. data/lib/irb/cmd/info.rb +0 -21
  89. data/lib/irb/cmd/pushws.rb +0 -45
  90. data/lib/irb/cmd/show_cmds.rb +0 -39
  91. data/lib/irb/cmd/show_doc.rb +0 -48
  92. data/lib/irb/cmd/show_source.rb +0 -113
  93. data/lib/irb/cmd/subirb.rb +0 -66
  94. data/lib/irb/extend-command.rb +0 -356
  95. data/lib/irb/src_encoding.rb +0 -7
@@ -1,356 +0,0 @@
1
- # frozen_string_literal: false
2
- #
3
- # irb/extend-command.rb - irb extend command
4
- # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
- #
6
-
7
- module IRB # :nodoc:
8
- # Installs the default irb extensions command bundle.
9
- module ExtendCommandBundle
10
- EXCB = ExtendCommandBundle # :nodoc:
11
-
12
- # See #install_alias_method.
13
- NO_OVERRIDE = 0
14
- # See #install_alias_method.
15
- OVERRIDE_PRIVATE_ONLY = 0x01
16
- # See #install_alias_method.
17
- OVERRIDE_ALL = 0x02
18
-
19
- # Quits the current irb context
20
- #
21
- # +ret+ is the optional signal or message to send to Context#exit
22
- #
23
- # Same as <code>IRB.CurrentContext.exit</code>.
24
- def irb_exit(ret = 0)
25
- irb_context.exit(ret)
26
- end
27
-
28
- # Displays current configuration.
29
- #
30
- # Modifying the configuration is achieved by sending a message to IRB.conf.
31
- def irb_context
32
- IRB.CurrentContext
33
- end
34
-
35
- @ALIASES = [
36
- [:context, :irb_context, NO_OVERRIDE],
37
- [:conf, :irb_context, NO_OVERRIDE],
38
- [:irb_quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
39
- [:exit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
40
- [:quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
41
- ]
42
-
43
-
44
- @EXTEND_COMMANDS = [
45
- [
46
- :irb_current_working_workspace, :CurrentWorkingWorkspace, "cmd/chws",
47
- [:cwws, NO_OVERRIDE],
48
- [:pwws, NO_OVERRIDE],
49
- [:irb_print_working_workspace, OVERRIDE_ALL],
50
- [:irb_cwws, OVERRIDE_ALL],
51
- [:irb_pwws, OVERRIDE_ALL],
52
- [:irb_current_working_binding, OVERRIDE_ALL],
53
- [:irb_print_working_binding, OVERRIDE_ALL],
54
- [:irb_cwb, OVERRIDE_ALL],
55
- [:irb_pwb, OVERRIDE_ALL],
56
- ],
57
- [
58
- :irb_change_workspace, :ChangeWorkspace, "cmd/chws",
59
- [:chws, NO_OVERRIDE],
60
- [:cws, NO_OVERRIDE],
61
- [:irb_chws, OVERRIDE_ALL],
62
- [:irb_cws, OVERRIDE_ALL],
63
- [:irb_change_binding, OVERRIDE_ALL],
64
- [:irb_cb, OVERRIDE_ALL],
65
- [:cb, NO_OVERRIDE],
66
- ],
67
-
68
- [
69
- :irb_workspaces, :Workspaces, "cmd/pushws",
70
- [:workspaces, NO_OVERRIDE],
71
- [:irb_bindings, OVERRIDE_ALL],
72
- [:bindings, NO_OVERRIDE],
73
- ],
74
- [
75
- :irb_push_workspace, :PushWorkspace, "cmd/pushws",
76
- [:pushws, NO_OVERRIDE],
77
- [:irb_pushws, OVERRIDE_ALL],
78
- [:irb_push_binding, OVERRIDE_ALL],
79
- [:irb_pushb, OVERRIDE_ALL],
80
- [:pushb, NO_OVERRIDE],
81
- ],
82
- [
83
- :irb_pop_workspace, :PopWorkspace, "cmd/pushws",
84
- [:popws, NO_OVERRIDE],
85
- [:irb_popws, OVERRIDE_ALL],
86
- [:irb_pop_binding, OVERRIDE_ALL],
87
- [:irb_popb, OVERRIDE_ALL],
88
- [:popb, NO_OVERRIDE],
89
- ],
90
-
91
- [
92
- :irb_load, :Load, "cmd/load"],
93
- [
94
- :irb_require, :Require, "cmd/load"],
95
- [
96
- :irb_source, :Source, "cmd/load",
97
- [:source, NO_OVERRIDE],
98
- ],
99
-
100
- [
101
- :irb, :IrbCommand, "cmd/subirb"],
102
- [
103
- :irb_jobs, :Jobs, "cmd/subirb",
104
- [:jobs, NO_OVERRIDE],
105
- ],
106
- [
107
- :irb_fg, :Foreground, "cmd/subirb",
108
- [:fg, NO_OVERRIDE],
109
- ],
110
- [
111
- :irb_kill, :Kill, "cmd/subirb",
112
- [:kill, OVERRIDE_PRIVATE_ONLY],
113
- ],
114
-
115
- [
116
- :irb_debug, :Debug, "cmd/debug",
117
- [:debug, NO_OVERRIDE],
118
- ],
119
- [
120
- :irb_edit, :Edit, "cmd/edit",
121
- [:edit, NO_OVERRIDE],
122
- ],
123
- [
124
- :irb_break, :Break, "cmd/break",
125
- ],
126
- [
127
- :irb_catch, :Catch, "cmd/catch",
128
- ],
129
- [
130
- :irb_next, :Next, "cmd/next"
131
- ],
132
- [
133
- :irb_delete, :Delete, "cmd/delete",
134
- [:delete, NO_OVERRIDE],
135
- ],
136
- [
137
- :irb_step, :Step, "cmd/step",
138
- [:step, NO_OVERRIDE],
139
- ],
140
- [
141
- :irb_continue, :Continue, "cmd/continue",
142
- [:continue, NO_OVERRIDE],
143
- ],
144
- [
145
- :irb_finish, :Finish, "cmd/finish",
146
- [:finish, NO_OVERRIDE],
147
- ],
148
- [
149
- :irb_backtrace, :Backtrace, "cmd/backtrace",
150
- [:backtrace, NO_OVERRIDE],
151
- [:bt, NO_OVERRIDE],
152
- ],
153
- [
154
- :irb_debug_info, :Info, "cmd/info",
155
- [:info, NO_OVERRIDE],
156
- ],
157
-
158
- [
159
- :irb_help, :Help, "cmd/help",
160
- [:help, NO_OVERRIDE],
161
- ],
162
-
163
- [
164
- :irb_show_doc, :ShowDoc, "cmd/show_doc",
165
- [:show_doc, NO_OVERRIDE],
166
- ],
167
-
168
- [
169
- :irb_info, :IrbInfo, "cmd/irb_info"
170
- ],
171
-
172
- [
173
- :irb_ls, :Ls, "cmd/ls",
174
- [:ls, NO_OVERRIDE],
175
- ],
176
-
177
- [
178
- :irb_measure, :Measure, "cmd/measure",
179
- [:measure, NO_OVERRIDE],
180
- ],
181
-
182
- [
183
- :irb_show_source, :ShowSource, "cmd/show_source",
184
- [:show_source, NO_OVERRIDE],
185
- ],
186
-
187
- [
188
- :irb_whereami, :Whereami, "cmd/whereami",
189
- [:whereami, NO_OVERRIDE],
190
- ],
191
- [
192
- :irb_show_cmds, :ShowCmds, "cmd/show_cmds",
193
- [:show_cmds, NO_OVERRIDE],
194
- ]
195
- ]
196
-
197
-
198
- @@commands = []
199
-
200
- def self.all_commands_info
201
- return @@commands unless @@commands.empty?
202
- user_aliases = IRB.CurrentContext.command_aliases.each_with_object({}) do |(alias_name, target), result|
203
- result[target] ||= []
204
- result[target] << alias_name
205
- end
206
-
207
- @EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
208
- if !defined?(ExtendCommand) || !ExtendCommand.const_defined?(cmd_class, false)
209
- require_relative load_file
210
- end
211
-
212
- klass = ExtendCommand.const_get(cmd_class, false)
213
- aliases = aliases.map { |a| a.first }
214
-
215
- if additional_aliases = user_aliases[cmd_name]
216
- aliases += additional_aliases
217
- end
218
-
219
- display_name = aliases.shift || cmd_name
220
- @@commands << { display_name: display_name, description: klass.description, category: klass.category }
221
- end
222
-
223
- @@commands
224
- end
225
-
226
- # Convert a command name to its implementation class if such command exists
227
- def self.load_command(command)
228
- command = command.to_sym
229
- @EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
230
- next if cmd_name != command && aliases.all? { |alias_name, _| alias_name != command }
231
-
232
- if !defined?(ExtendCommand) || !ExtendCommand.const_defined?(cmd_class, false)
233
- require_relative load_file
234
- end
235
- return ExtendCommand.const_get(cmd_class, false)
236
- end
237
- nil
238
- end
239
-
240
- # Installs the default irb commands.
241
- def self.install_extend_commands
242
- for args in @EXTEND_COMMANDS
243
- def_extend_command(*args)
244
- end
245
- end
246
-
247
- # Evaluate the given +cmd_name+ on the given +cmd_class+ Class.
248
- #
249
- # Will also define any given +aliases+ for the method.
250
- #
251
- # The optional +load_file+ parameter will be required within the method
252
- # definition.
253
- def self.def_extend_command(cmd_name, cmd_class, load_file, *aliases)
254
- case cmd_class
255
- when Symbol
256
- cmd_class = cmd_class.id2name
257
- when String
258
- when Class
259
- cmd_class = cmd_class.name
260
- end
261
-
262
- line = __LINE__; eval %[
263
- def #{cmd_name}(*opts, **kwargs, &b)
264
- Kernel.require_relative "#{load_file}"
265
- ::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, *opts, **kwargs, &b)
266
- end
267
- ], nil, __FILE__, line
268
-
269
- for ali, flag in aliases
270
- @ALIASES.push [ali, cmd_name, flag]
271
- end
272
- end
273
-
274
- # Installs alias methods for the default irb commands, see
275
- # ::install_extend_commands.
276
- def install_alias_method(to, from, override = NO_OVERRIDE)
277
- to = to.id2name unless to.kind_of?(String)
278
- from = from.id2name unless from.kind_of?(String)
279
-
280
- if override == OVERRIDE_ALL or
281
- (override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
282
- (override == NO_OVERRIDE) && !respond_to?(to, true)
283
- target = self
284
- (class << self; self; end).instance_eval{
285
- if target.respond_to?(to, true) &&
286
- !target.respond_to?(EXCB.irb_original_method_name(to), true)
287
- alias_method(EXCB.irb_original_method_name(to), to)
288
- end
289
- alias_method to, from
290
- }
291
- else
292
- Kernel.warn "irb: warn: can't alias #{to} from #{from}.\n"
293
- end
294
- end
295
-
296
- def self.irb_original_method_name(method_name) # :nodoc:
297
- "irb_" + method_name + "_org"
298
- end
299
-
300
- # Installs alias methods for the default irb commands on the given object
301
- # using #install_alias_method.
302
- def self.extend_object(obj)
303
- unless (class << obj; ancestors; end).include?(EXCB)
304
- super
305
- for ali, com, flg in @ALIASES
306
- obj.install_alias_method(ali, com, flg)
307
- end
308
- end
309
- end
310
-
311
- install_extend_commands
312
- end
313
-
314
- # Extends methods for the Context module
315
- module ContextExtender
316
- CE = ContextExtender # :nodoc:
317
-
318
- @EXTEND_COMMANDS = [
319
- [:eval_history=, "ext/history.rb"],
320
- [:use_tracer=, "ext/tracer.rb"],
321
- [:use_loader=, "ext/use-loader.rb"],
322
- [:save_history=, "ext/save-history.rb"],
323
- ]
324
-
325
- # Installs the default context extensions as irb commands:
326
- #
327
- # Context#eval_history=:: +irb/ext/history.rb+
328
- # Context#use_tracer=:: +irb/ext/tracer.rb+
329
- # Context#use_loader=:: +irb/ext/use-loader.rb+
330
- # Context#save_history=:: +irb/ext/save-history.rb+
331
- def self.install_extend_commands
332
- for args in @EXTEND_COMMANDS
333
- def_extend_command(*args)
334
- end
335
- end
336
-
337
- # Evaluate the given +command+ from the given +load_file+ on the Context
338
- # module.
339
- #
340
- # Will also define any given +aliases+ for the method.
341
- def self.def_extend_command(cmd_name, load_file, *aliases)
342
- line = __LINE__; Context.module_eval %[
343
- def #{cmd_name}(*opts, &b)
344
- Context.module_eval {remove_method(:#{cmd_name})}
345
- require_relative "#{load_file}"
346
- __send__ :#{cmd_name}, *opts, &b
347
- end
348
- for ali in aliases
349
- alias_method ali, cmd_name
350
- end
351
- ], __FILE__, line
352
- end
353
-
354
- CE.install_extend_commands
355
- end
356
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: false
2
- # DO NOT WRITE ANY MAGIC COMMENT HERE.
3
- module IRB
4
- def self.default_src_encoding
5
- return __ENCODING__
6
- end
7
- end