irb 1.12.0 → 1.13.0

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -11
  3. data/Rakefile +10 -0
  4. data/irb.gemspec +1 -1
  5. data/lib/irb/cmd/nop.rb +1 -1
  6. data/lib/irb/color.rb +2 -2
  7. data/lib/irb/command/backtrace.rb +2 -6
  8. data/lib/irb/command/base.rb +7 -9
  9. data/lib/irb/command/break.rb +2 -6
  10. data/lib/irb/command/catch.rb +2 -6
  11. data/lib/irb/command/chws.rb +11 -5
  12. data/lib/irb/command/context.rb +16 -0
  13. data/lib/irb/command/continue.rb +2 -2
  14. data/lib/irb/command/debug.rb +8 -1
  15. data/lib/irb/command/delete.rb +2 -2
  16. data/lib/irb/command/disable_irb.rb +19 -0
  17. data/lib/irb/command/edit.rb +6 -13
  18. data/lib/irb/command/exit.rb +1 -3
  19. data/lib/irb/command/finish.rb +2 -2
  20. data/lib/irb/command/force_exit.rb +1 -3
  21. data/lib/irb/command/help.rb +8 -17
  22. data/lib/irb/command/history.rb +4 -6
  23. data/lib/irb/command/info.rb +2 -6
  24. data/lib/irb/command/internal_helpers.rb +27 -0
  25. data/lib/irb/command/irb_info.rb +2 -2
  26. data/lib/irb/command/load.rb +20 -3
  27. data/lib/irb/command/ls.rb +20 -10
  28. data/lib/irb/command/measure.rb +12 -6
  29. data/lib/irb/command/next.rb +2 -2
  30. data/lib/irb/command/pushws.rb +10 -5
  31. data/lib/irb/command/show_doc.rb +9 -18
  32. data/lib/irb/command/show_source.rb +5 -12
  33. data/lib/irb/command/step.rb +2 -2
  34. data/lib/irb/command/subirb.rb +28 -12
  35. data/lib/irb/command/whereami.rb +1 -1
  36. data/lib/irb/command.rb +8 -303
  37. data/lib/irb/completion.rb +16 -5
  38. data/lib/irb/context.rb +21 -19
  39. data/lib/irb/default_commands.rb +260 -0
  40. data/lib/irb/ext/change-ws.rb +3 -5
  41. data/lib/irb/ext/multi-irb.rb +4 -4
  42. data/lib/irb/ext/workspaces.rb +3 -4
  43. data/lib/irb/help.rb +1 -1
  44. data/lib/irb/helper_method/base.rb +16 -0
  45. data/lib/irb/helper_method/conf.rb +11 -0
  46. data/lib/irb/helper_method.rb +29 -0
  47. data/lib/irb/history.rb +6 -3
  48. data/lib/irb/init.rb +60 -44
  49. data/lib/irb/input-method.rb +18 -10
  50. data/lib/irb/lc/error.rb +0 -5
  51. data/lib/irb/lc/ja/error.rb +0 -5
  52. data/lib/irb/lc/ja/help-message +10 -0
  53. data/lib/irb/statement.rb +5 -27
  54. data/lib/irb/version.rb +2 -2
  55. data/lib/irb/workspace.rb +18 -2
  56. data/lib/irb.rb +675 -624
  57. metadata +12 -5
@@ -0,0 +1,260 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "command"
4
+ require_relative "command/internal_helpers"
5
+ require_relative "command/context"
6
+ require_relative "command/exit"
7
+ require_relative "command/force_exit"
8
+ require_relative "command/chws"
9
+ require_relative "command/pushws"
10
+ require_relative "command/subirb"
11
+ require_relative "command/load"
12
+ require_relative "command/debug"
13
+ require_relative "command/edit"
14
+ require_relative "command/break"
15
+ require_relative "command/catch"
16
+ require_relative "command/next"
17
+ require_relative "command/delete"
18
+ require_relative "command/step"
19
+ require_relative "command/continue"
20
+ require_relative "command/finish"
21
+ require_relative "command/backtrace"
22
+ require_relative "command/info"
23
+ require_relative "command/help"
24
+ require_relative "command/show_doc"
25
+ require_relative "command/irb_info"
26
+ require_relative "command/ls"
27
+ require_relative "command/measure"
28
+ require_relative "command/show_source"
29
+ require_relative "command/whereami"
30
+ require_relative "command/history"
31
+
32
+ module IRB
33
+ module Command
34
+ NO_OVERRIDE = 0
35
+ OVERRIDE_PRIVATE_ONLY = 0x01
36
+ OVERRIDE_ALL = 0x02
37
+
38
+ class << self
39
+ # This API is for IRB's internal use only and may change at any time.
40
+ # Please do NOT use it.
41
+ def _register_with_aliases(name, command_class, *aliases)
42
+ @commands[name.to_sym] = [command_class, aliases]
43
+ end
44
+
45
+ def all_commands_info
46
+ user_aliases = IRB.CurrentContext.command_aliases.each_with_object({}) do |(alias_name, target), result|
47
+ result[target] ||= []
48
+ result[target] << alias_name
49
+ end
50
+
51
+ commands.map do |command_name, (command_class, aliases)|
52
+ aliases = aliases.map { |a| a.first }
53
+
54
+ if additional_aliases = user_aliases[command_name]
55
+ aliases += additional_aliases
56
+ end
57
+
58
+ display_name = aliases.shift || command_name
59
+ {
60
+ display_name: display_name,
61
+ description: command_class.description,
62
+ category: command_class.category
63
+ }
64
+ end
65
+ end
66
+
67
+ def command_override_policies
68
+ @@command_override_policies ||= commands.flat_map do |cmd_name, (cmd_class, aliases)|
69
+ [[cmd_name, OVERRIDE_ALL]] + aliases
70
+ end.to_h
71
+ end
72
+
73
+ def execute_as_command?(name, public_method:, private_method:)
74
+ case command_override_policies[name]
75
+ when OVERRIDE_ALL
76
+ true
77
+ when OVERRIDE_PRIVATE_ONLY
78
+ !public_method
79
+ when NO_OVERRIDE
80
+ !public_method && !private_method
81
+ end
82
+ end
83
+
84
+ def command_names
85
+ command_override_policies.keys.map(&:to_s)
86
+ end
87
+
88
+ # Convert a command name to its implementation class if such command exists
89
+ def load_command(command)
90
+ command = command.to_sym
91
+ commands.each do |command_name, (command_class, aliases)|
92
+ if command_name == command || aliases.any? { |alias_name, _| alias_name == command }
93
+ return command_class
94
+ end
95
+ end
96
+ nil
97
+ end
98
+ end
99
+
100
+ _register_with_aliases(:irb_context, Command::Context,
101
+ [:context, NO_OVERRIDE]
102
+ )
103
+
104
+ _register_with_aliases(:irb_exit, Command::Exit,
105
+ [:exit, OVERRIDE_PRIVATE_ONLY],
106
+ [:quit, OVERRIDE_PRIVATE_ONLY],
107
+ [:irb_quit, OVERRIDE_PRIVATE_ONLY]
108
+ )
109
+
110
+ _register_with_aliases(:irb_exit!, Command::ForceExit,
111
+ [:exit!, OVERRIDE_PRIVATE_ONLY]
112
+ )
113
+
114
+ _register_with_aliases(:irb_current_working_workspace, Command::CurrentWorkingWorkspace,
115
+ [:cwws, NO_OVERRIDE],
116
+ [:pwws, NO_OVERRIDE],
117
+ [:irb_print_working_workspace, OVERRIDE_ALL],
118
+ [:irb_cwws, OVERRIDE_ALL],
119
+ [:irb_pwws, OVERRIDE_ALL],
120
+ [:irb_current_working_binding, OVERRIDE_ALL],
121
+ [:irb_print_working_binding, OVERRIDE_ALL],
122
+ [:irb_cwb, OVERRIDE_ALL],
123
+ [:irb_pwb, OVERRIDE_ALL],
124
+ )
125
+
126
+ _register_with_aliases(:irb_change_workspace, Command::ChangeWorkspace,
127
+ [:chws, NO_OVERRIDE],
128
+ [:cws, NO_OVERRIDE],
129
+ [:irb_chws, OVERRIDE_ALL],
130
+ [:irb_cws, OVERRIDE_ALL],
131
+ [:irb_change_binding, OVERRIDE_ALL],
132
+ [:irb_cb, OVERRIDE_ALL],
133
+ [:cb, NO_OVERRIDE],
134
+ )
135
+
136
+ _register_with_aliases(:irb_workspaces, Command::Workspaces,
137
+ [:workspaces, NO_OVERRIDE],
138
+ [:irb_bindings, OVERRIDE_ALL],
139
+ [:bindings, NO_OVERRIDE],
140
+ )
141
+
142
+ _register_with_aliases(:irb_push_workspace, Command::PushWorkspace,
143
+ [:pushws, NO_OVERRIDE],
144
+ [:irb_pushws, OVERRIDE_ALL],
145
+ [:irb_push_binding, OVERRIDE_ALL],
146
+ [:irb_pushb, OVERRIDE_ALL],
147
+ [:pushb, NO_OVERRIDE],
148
+ )
149
+
150
+ _register_with_aliases(:irb_pop_workspace, Command::PopWorkspace,
151
+ [:popws, NO_OVERRIDE],
152
+ [:irb_popws, OVERRIDE_ALL],
153
+ [:irb_pop_binding, OVERRIDE_ALL],
154
+ [:irb_popb, OVERRIDE_ALL],
155
+ [:popb, NO_OVERRIDE],
156
+ )
157
+
158
+ _register_with_aliases(:irb_load, Command::Load)
159
+ _register_with_aliases(:irb_require, Command::Require)
160
+ _register_with_aliases(:irb_source, Command::Source,
161
+ [:source, NO_OVERRIDE]
162
+ )
163
+
164
+ _register_with_aliases(:irb, Command::IrbCommand)
165
+ _register_with_aliases(:irb_jobs, Command::Jobs,
166
+ [:jobs, NO_OVERRIDE]
167
+ )
168
+ _register_with_aliases(:irb_fg, Command::Foreground,
169
+ [:fg, NO_OVERRIDE]
170
+ )
171
+ _register_with_aliases(:irb_kill, Command::Kill,
172
+ [:kill, OVERRIDE_PRIVATE_ONLY]
173
+ )
174
+
175
+ _register_with_aliases(:irb_debug, Command::Debug,
176
+ [:debug, NO_OVERRIDE]
177
+ )
178
+ _register_with_aliases(:irb_edit, Command::Edit,
179
+ [:edit, NO_OVERRIDE]
180
+ )
181
+
182
+ _register_with_aliases(:irb_break, Command::Break)
183
+ _register_with_aliases(:irb_catch, Command::Catch)
184
+ _register_with_aliases(:irb_next, Command::Next)
185
+ _register_with_aliases(:irb_delete, Command::Delete,
186
+ [:delete, NO_OVERRIDE]
187
+ )
188
+
189
+ _register_with_aliases(:irb_step, Command::Step,
190
+ [:step, NO_OVERRIDE]
191
+ )
192
+ _register_with_aliases(:irb_continue, Command::Continue,
193
+ [:continue, NO_OVERRIDE]
194
+ )
195
+ _register_with_aliases(:irb_finish, Command::Finish,
196
+ [:finish, NO_OVERRIDE]
197
+ )
198
+ _register_with_aliases(:irb_backtrace, Command::Backtrace,
199
+ [:backtrace, NO_OVERRIDE],
200
+ [:bt, NO_OVERRIDE]
201
+ )
202
+
203
+ _register_with_aliases(:irb_debug_info, Command::Info,
204
+ [:info, NO_OVERRIDE]
205
+ )
206
+
207
+ _register_with_aliases(:irb_help, Command::Help,
208
+ [:help, NO_OVERRIDE],
209
+ [:show_cmds, NO_OVERRIDE]
210
+ )
211
+
212
+ _register_with_aliases(:irb_show_doc, Command::ShowDoc,
213
+ [:show_doc, NO_OVERRIDE]
214
+ )
215
+
216
+ _register_with_aliases(:irb_info, Command::IrbInfo)
217
+
218
+ _register_with_aliases(:irb_ls, Command::Ls,
219
+ [:ls, NO_OVERRIDE]
220
+ )
221
+
222
+ _register_with_aliases(:irb_measure, Command::Measure,
223
+ [:measure, NO_OVERRIDE]
224
+ )
225
+
226
+ _register_with_aliases(:irb_show_source, Command::ShowSource,
227
+ [:show_source, NO_OVERRIDE]
228
+ )
229
+
230
+ _register_with_aliases(:irb_whereami, Command::Whereami,
231
+ [:whereami, NO_OVERRIDE]
232
+ )
233
+
234
+ _register_with_aliases(:irb_history, Command::History,
235
+ [:history, NO_OVERRIDE],
236
+ [:hist, NO_OVERRIDE]
237
+ )
238
+ end
239
+
240
+ ExtendCommand = Command
241
+
242
+ # For backward compatibility, we need to keep this module:
243
+ # - As a container of helper methods
244
+ # - As a place to register commands with the deprecated def_extend_command method
245
+ module ExtendCommandBundle
246
+ # For backward compatibility
247
+ NO_OVERRIDE = Command::NO_OVERRIDE
248
+ OVERRIDE_PRIVATE_ONLY = Command::OVERRIDE_PRIVATE_ONLY
249
+ OVERRIDE_ALL = Command::OVERRIDE_ALL
250
+
251
+ # Deprecated. Doesn't have any effect.
252
+ @EXTEND_COMMANDS = []
253
+
254
+ # Drepcated. Use Command.regiser instead.
255
+ def self.def_extend_command(cmd_name, cmd_class, _, *aliases)
256
+ Command._register_with_aliases(cmd_name, cmd_class, *aliases)
257
+ Command.class_variable_set(:@@command_override_policies, nil)
258
+ end
259
+ end
260
+ end
@@ -29,11 +29,9 @@ module IRB # :nodoc:
29
29
  return main
30
30
  end
31
31
 
32
- replace_workspace(WorkSpace.new(_main[0]))
33
-
34
- if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
35
- main.extend ExtendCommandBundle
36
- end
32
+ workspace = WorkSpace.new(_main[0])
33
+ replace_workspace(workspace)
34
+ workspace.load_helper_methods_to_main
37
35
  end
38
36
  end
39
37
  end
@@ -5,7 +5,7 @@
5
5
  #
6
6
 
7
7
  module IRB
8
- class JobManager
8
+ class JobManager # :nodoc:
9
9
 
10
10
  # Creates a new JobManager object
11
11
  def initialize
@@ -166,12 +166,12 @@ module IRB
166
166
  @JobManager = JobManager.new
167
167
 
168
168
  # The current JobManager in the session
169
- def IRB.JobManager
169
+ def IRB.JobManager # :nodoc:
170
170
  @JobManager
171
171
  end
172
172
 
173
173
  # The current Context in this session
174
- def IRB.CurrentContext
174
+ def IRB.CurrentContext # :nodoc:
175
175
  IRB.JobManager.irb(Thread.current).context
176
176
  end
177
177
 
@@ -179,7 +179,7 @@ module IRB
179
179
  #
180
180
  # The optional +file+ argument is given to Context.new, along with the
181
181
  # workspace created with the remaining arguments, see WorkSpace.new
182
- def IRB.irb(file = nil, *main)
182
+ def IRB.irb(file = nil, *main) # :nodoc:
183
183
  workspace = WorkSpace.new(*main)
184
184
  parent_thread = Thread.current
185
185
  Thread.start do
@@ -19,10 +19,9 @@ module IRB # :nodoc:
19
19
  @workspace_stack.push current_workspace, previous_workspace
20
20
  end
21
21
  else
22
- @workspace_stack.push WorkSpace.new(workspace.binding, _main[0])
23
- if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
24
- main.extend ExtendCommandBundle
25
- end
22
+ new_workspace = WorkSpace.new(workspace.binding, _main[0])
23
+ @workspace_stack.push new_workspace
24
+ new_workspace.load_helper_methods_to_main
26
25
  end
27
26
  end
28
27
 
data/lib/irb/help.rb CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  module IRB
8
8
  # Outputs the irb help message, see IRB@Command-Line+Options.
9
- def IRB.print_usage
9
+ def IRB.print_usage # :nodoc:
10
10
  lc = IRB.conf[:LC_MESSAGES]
11
11
  path = lc.find("irb/help-message")
12
12
  space_line = false
@@ -0,0 +1,16 @@
1
+ require "singleton"
2
+
3
+ module IRB
4
+ module HelperMethod
5
+ class Base
6
+ include Singleton
7
+
8
+ class << self
9
+ def description(description = nil)
10
+ @description = description if description
11
+ @description
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module IRB
2
+ module HelperMethod
3
+ class Conf < Base
4
+ description "Returns the current context."
5
+
6
+ def execute
7
+ IRB.CurrentContext
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "helper_method/base"
2
+
3
+ module IRB
4
+ module HelperMethod
5
+ @helper_methods = {}
6
+
7
+ class << self
8
+ attr_reader :helper_methods
9
+
10
+ def register(name, helper_class)
11
+ @helper_methods[name] = helper_class
12
+
13
+ if defined?(HelpersContainer)
14
+ HelpersContainer.install_helper_methods
15
+ end
16
+ end
17
+
18
+ def all_helper_methods_info
19
+ @helper_methods.map do |name, helper_class|
20
+ { display_name: name, description: helper_class.description }
21
+ end
22
+ end
23
+ end
24
+
25
+ # Default helper_methods
26
+ require_relative "helper_method/conf"
27
+ register(:conf, HelperMethod::Conf)
28
+ end
29
+ end
data/lib/irb/history.rb CHANGED
@@ -16,8 +16,8 @@ module IRB
16
16
  if history_file = IRB.conf[:HISTORY_FILE]
17
17
  history_file = File.expand_path(history_file)
18
18
  end
19
- history_file = IRB.rc_files("_history").first unless history_file
20
- if File.exist?(history_file)
19
+ history_file = IRB.rc_file("_history") unless history_file
20
+ if history_file && File.exist?(history_file)
21
21
  File.open(history_file, "r:#{IRB.conf[:LC_MESSAGES].encoding}") do |f|
22
22
  f.each { |l|
23
23
  l = l.chomp
@@ -41,7 +41,10 @@ module IRB
41
41
  if history_file = IRB.conf[:HISTORY_FILE]
42
42
  history_file = File.expand_path(history_file)
43
43
  end
44
- history_file = IRB.rc_files("_history").first unless history_file
44
+ history_file = IRB.rc_file("_history") unless history_file
45
+
46
+ # When HOME and XDG_CONFIG_HOME are not available, history_file might be nil
47
+ return unless history_file
45
48
 
46
49
  # Change the permission of a file that already exists[BUG #7694]
47
50
  begin
data/lib/irb/init.rb CHANGED
@@ -395,10 +395,8 @@ module IRB # :nodoc:
395
395
  # Run the config file
396
396
  def IRB.run_config
397
397
  if @CONF[:RC]
398
- rc_files.each do |rc|
399
- # Because rc_file always returns `HOME/.irbrc` even if no rc file is present, we can't warn users about missing rc files.
400
- # Otherwise, it'd be very noisy.
401
- load rc if File.exist?(rc)
398
+ irbrc_files.each do |rc|
399
+ load rc
402
400
  rescue StandardError, ScriptError => e
403
401
  warn "Error loading RC file '#{rc}':\n#{e.full_message(highlight: false)}"
404
402
  end
@@ -406,53 +404,27 @@ module IRB # :nodoc:
406
404
  end
407
405
 
408
406
  IRBRC_EXT = "rc"
409
- def IRB.rc_file(ext = IRBRC_EXT)
410
- warn "rc_file is deprecated, please use rc_files instead."
411
- rc_files(ext).first
412
- end
413
-
414
- def IRB.rc_files(ext = IRBRC_EXT)
415
- if !@CONF[:RC_NAME_GENERATOR]
416
- @CONF[:RC_NAME_GENERATOR] ||= []
417
- existing_rc_file_generators = []
418
407
 
419
- rc_file_generators do |rcgen|
420
- @CONF[:RC_NAME_GENERATOR] << rcgen
421
- existing_rc_file_generators << rcgen if File.exist?(rcgen.call(ext))
422
- end
408
+ def IRB.rc_file(ext)
409
+ prepare_irbrc_name_generators
423
410
 
424
- if existing_rc_file_generators.any?
425
- @CONF[:RC_NAME_GENERATOR] = existing_rc_file_generators
426
- end
411
+ # When irbrc exist in default location
412
+ if (rcgen = @existing_rc_name_generators.first)
413
+ return rcgen.call(ext)
427
414
  end
428
415
 
429
- @CONF[:RC_NAME_GENERATOR].map do |rc|
430
- rc_file = rc.call(ext)
431
- fail IllegalRCNameGenerator unless rc_file.is_a?(String)
432
- rc_file
416
+ # When irbrc does not exist in default location
417
+ rc_file_generators do |rcgen|
418
+ return rcgen.call(ext)
433
419
  end
420
+
421
+ # When HOME and XDG_CONFIG_HOME are not available
422
+ nil
434
423
  end
435
424
 
436
- # enumerate possible rc-file base name generators
437
- def IRB.rc_file_generators
438
- if irbrc = ENV["IRBRC"]
439
- yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
440
- end
441
- if xdg_config_home = ENV["XDG_CONFIG_HOME"]
442
- irb_home = File.join(xdg_config_home, "irb")
443
- if File.directory?(irb_home)
444
- yield proc{|rc| irb_home + "/irb#{rc}"}
445
- end
446
- end
447
- if home = ENV["HOME"]
448
- yield proc{|rc| home+"/.irb#{rc}"}
449
- yield proc{|rc| home+"/.config/irb/irb#{rc}"}
450
- end
451
- current_dir = Dir.pwd
452
- yield proc{|rc| current_dir+"/.irb#{rc}"}
453
- yield proc{|rc| current_dir+"/irb#{rc.sub(/\A_?/, '.')}"}
454
- yield proc{|rc| current_dir+"/_irb#{rc}"}
455
- yield proc{|rc| current_dir+"/$irb#{rc}"}
425
+ def IRB.irbrc_files
426
+ prepare_irbrc_name_generators
427
+ @irbrc_files
456
428
  end
457
429
 
458
430
  # loading modules
@@ -468,6 +440,50 @@ module IRB # :nodoc:
468
440
 
469
441
  class << IRB
470
442
  private
443
+
444
+ def prepare_irbrc_name_generators
445
+ return if @existing_rc_name_generators
446
+
447
+ @existing_rc_name_generators = []
448
+ @irbrc_files = []
449
+ rc_file_generators do |rcgen|
450
+ irbrc = rcgen.call(IRBRC_EXT)
451
+ if File.exist?(irbrc)
452
+ @irbrc_files << irbrc
453
+ @existing_rc_name_generators << rcgen
454
+ end
455
+ end
456
+ generate_current_dir_irbrc_files.each do |irbrc|
457
+ @irbrc_files << irbrc if File.exist?(irbrc)
458
+ end
459
+ @irbrc_files.uniq!
460
+ end
461
+
462
+ # enumerate possible rc-file base name generators
463
+ def rc_file_generators
464
+ if irbrc = ENV["IRBRC"]
465
+ yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
466
+ end
467
+ if xdg_config_home = ENV["XDG_CONFIG_HOME"]
468
+ irb_home = File.join(xdg_config_home, "irb")
469
+ if File.directory?(irb_home)
470
+ yield proc{|rc| irb_home + "/irb#{rc}"}
471
+ end
472
+ end
473
+ if home = ENV["HOME"]
474
+ yield proc{|rc| home+"/.irb#{rc}"}
475
+ if xdg_config_home.nil? || xdg_config_home.empty?
476
+ yield proc{|rc| home+"/.config/irb/irb#{rc}"}
477
+ end
478
+ end
479
+ end
480
+
481
+ # possible irbrc files in current directory
482
+ def generate_current_dir_irbrc_files
483
+ current_dir = Dir.pwd
484
+ %w[.irbrc irbrc _irbrc $irbrc].map { |file| "#{current_dir}/#{file}" }
485
+ end
486
+
471
487
  def set_encoding(extern, intern = nil, override: true)
472
488
  verbose, $VERBOSE = $VERBOSE, nil
473
489
  Encoding.default_external = extern unless extern.nil? || extern.empty?
@@ -308,6 +308,20 @@ module IRB
308
308
  @completor.doc_namespace(preposing, matched, postposing, bind: bind)
309
309
  end
310
310
 
311
+ def rdoc_ri_driver
312
+ return @rdoc_ri_driver if defined?(@rdoc_ri_driver)
313
+
314
+ begin
315
+ require 'rdoc'
316
+ rescue LoadError
317
+ @rdoc_ri_driver = nil
318
+ else
319
+ options = {}
320
+ options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
321
+ @rdoc_ri_driver = RDoc::RI::Driver.new(options)
322
+ end
323
+ end
324
+
311
325
  def show_doc_dialog_proc
312
326
  input_method = self # self is changed in the lambda below.
313
327
  ->() {
@@ -331,9 +345,7 @@ module IRB
331
345
 
332
346
  show_easter_egg = name&.match?(/\ARubyVM/) && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
333
347
 
334
- options = {}
335
- options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
336
- driver = RDoc::RI::Driver.new(options)
348
+ driver = input_method.rdoc_ri_driver
337
349
 
338
350
  if key.match?(dialog.name)
339
351
  if show_easter_egg
@@ -421,12 +433,9 @@ module IRB
421
433
  }
422
434
  end
423
435
 
424
- def display_document(matched, driver: nil)
425
- begin
426
- require 'rdoc'
427
- rescue LoadError
428
- return
429
- end
436
+ def display_document(matched)
437
+ driver = rdoc_ri_driver
438
+ return unless driver
430
439
 
431
440
  if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
432
441
  IRB.__send__(:easter_egg)
@@ -436,7 +445,6 @@ module IRB
436
445
  namespace = retrieve_doc_namespace(matched)
437
446
  return unless namespace
438
447
 
439
- driver ||= RDoc::RI::Driver.new
440
448
  if namespace.is_a?(Array)
441
449
  out = RDoc::Markup::Document.new
442
450
  namespace.each do |m|
data/lib/irb/lc/error.rb CHANGED
@@ -47,11 +47,6 @@ module IRB
47
47
  super("Undefined prompt mode(#{val}).")
48
48
  end
49
49
  end
50
- class IllegalRCGenerator < StandardError
51
- def initialize
52
- super("Define illegal RC_NAME_GENERATOR.")
53
- end
54
- end
55
50
 
56
51
  # :startdoc:
57
52
  end
@@ -47,11 +47,6 @@ module IRB
47
47
  super("プロンプトモード(#{val})は定義されていません.")
48
48
  end
49
49
  end
50
- class IllegalRCGenerator < StandardError
51
- def initialize
52
- super("RC_NAME_GENERATORが正しく定義されていません.")
53
- end
54
- end
55
50
 
56
51
  # :startdoc:
57
52
  end
@@ -9,10 +9,18 @@ Usage: irb.rb [options] [programfile] [arguments]
9
9
  -W[level=2] ruby -W と同じ.
10
10
  --context-mode n 新しいワークスペースを作成した時に関連する Binding
11
11
  オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
12
+ --extra-doc-dir 指定したディレクトリのドキュメントを追加で読み込む.
12
13
  --echo 実行結果を表示する(デフォルト).
13
14
  --noecho 実行結果を表示しない.
15
+ --echo-on-assignment
16
+ 代入結果を表示する.
17
+ --noecho-on-assignment
18
+ 代入結果を表示しない.
19
+ --truncate-echo-on-assignment
20
+ truncateされた代入結果を表示する(デフォルト).
14
21
  --inspect 結果出力にinspectを用いる.
15
22
  --noinspect 結果出力にinspectを用いない.
23
+ --no-pager ページャを使用しない.
16
24
  --multiline マルチラインエディタを利用する.
17
25
  --nomultiline マルチラインエディタを利用しない.
18
26
  --singleline シングルラインエディタを利用する.
@@ -34,6 +42,8 @@ Usage: irb.rb [options] [programfile] [arguments]
34
42
  --sample-book-mode/--simple-prompt
35
43
  非常にシンプルなプロンプトを用いるモードです.
36
44
  --noprompt プロンプト表示を行なわない.
45
+ --script スクリプトモード(最初の引数をスクリプトファイルとして扱う、デフォルト)
46
+ --noscript 引数をargvとして扱う.
37
47
  --single-irb irb 中で self を実行して得られるオブジェクトをサ
38
48
  ブ irb と共有する.
39
49
  --tracer コマンド実行時にトレースを行なう.