irb 1.11.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/README.md +11 -9
  4. data/Rakefile +1 -1
  5. data/lib/irb/cmd/nop.rb +3 -52
  6. data/lib/irb/{cmd → command}/backtrace.rb +1 -1
  7. data/lib/irb/command/base.rb +64 -0
  8. data/lib/irb/{cmd → command}/break.rb +1 -1
  9. data/lib/irb/{cmd → command}/catch.rb +1 -1
  10. data/lib/irb/{cmd → command}/chws.rb +4 -6
  11. data/lib/irb/{cmd → command}/continue.rb +1 -1
  12. data/lib/irb/{cmd → command}/debug.rb +3 -4
  13. data/lib/irb/{cmd → command}/delete.rb +1 -1
  14. data/lib/irb/command/edit.rb +70 -0
  15. data/lib/irb/{cmd → command}/exit.rb +2 -4
  16. data/lib/irb/{cmd → command}/finish.rb +1 -1
  17. data/lib/irb/command/force_exit.rb +20 -0
  18. data/lib/irb/command/help.rb +84 -0
  19. data/lib/irb/{cmd → command}/history.rb +3 -3
  20. data/lib/irb/{cmd → command}/info.rb +1 -1
  21. data/lib/irb/{cmd → command}/irb_info.rb +5 -6
  22. data/lib/irb/{cmd → command}/load.rb +3 -5
  23. data/lib/irb/{cmd → command}/ls.rb +10 -4
  24. data/lib/irb/{cmd → command}/measure.rb +2 -4
  25. data/lib/irb/{cmd → command}/next.rb +1 -1
  26. data/lib/irb/{cmd → command}/pushws.rb +20 -5
  27. data/lib/irb/{cmd → command}/show_doc.rb +17 -5
  28. data/lib/irb/{cmd → command}/show_source.rb +26 -10
  29. data/lib/irb/{cmd → command}/step.rb +1 -1
  30. data/lib/irb/{cmd → command}/subirb.rb +3 -5
  31. data/lib/irb/{cmd → command}/whereami.rb +2 -4
  32. data/lib/irb/{extend-command.rb → command.rb} +50 -86
  33. data/lib/irb/completion.rb +1 -1
  34. data/lib/irb/context.rb +63 -20
  35. data/lib/irb/ext/change-ws.rb +4 -4
  36. data/lib/irb/ext/eval_history.rb +3 -3
  37. data/lib/irb/ext/loader.rb +4 -4
  38. data/lib/irb/ext/multi-irb.rb +1 -1
  39. data/lib/irb/ext/tracer.rb +12 -51
  40. data/lib/irb/ext/use-loader.rb +6 -8
  41. data/lib/irb/ext/workspaces.rb +11 -34
  42. data/lib/irb/frame.rb +1 -1
  43. data/lib/irb/help.rb +1 -1
  44. data/lib/irb/history.rb +12 -4
  45. data/lib/irb/init.rb +28 -17
  46. data/lib/irb/input-method.rb +18 -2
  47. data/lib/irb/inspector.rb +3 -3
  48. data/lib/irb/lc/error.rb +1 -6
  49. data/lib/irb/lc/ja/error.rb +1 -6
  50. data/lib/irb/locale.rb +2 -2
  51. data/lib/irb/nesting_parser.rb +13 -3
  52. data/lib/irb/notifier.rb +1 -1
  53. data/lib/irb/output-method.rb +2 -8
  54. data/lib/irb/ruby-lex.rb +2 -2
  55. data/lib/irb/source_finder.rb +98 -38
  56. data/lib/irb/statement.rb +25 -3
  57. data/lib/irb/version.rb +3 -3
  58. data/lib/irb/workspace.rb +4 -4
  59. data/lib/irb/ws-for-case-2.rb +1 -1
  60. data/lib/irb/xmp.rb +1 -1
  61. data/lib/irb.rb +38 -32
  62. metadata +30 -29
  63. data/lib/irb/cmd/edit.rb +0 -60
  64. data/lib/irb/cmd/help.rb +0 -23
  65. data/lib/irb/cmd/show_cmds.rb +0 -59
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
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
- @workspace.evaluate "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
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
- @workspace.evaluate("__ = IRB.conf[:__TMP__EHV__]")
52
+ workspace.evaluate("__ = IRB.conf[:__TMP__EHV__]")
53
53
  IRB.conf.delete(:__TMP_EHV__)
54
54
  end
55
55
  else
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
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 = @irb_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
- @irb_path = path
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
- @irb_path = back_path
122
+ self.irb_path = back_path
123
123
  @irb.scanner = back_scanner
124
124
  end
125
125
  end
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/multi-irb.rb - multiple irb module
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -1,78 +1,39 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/lib/tracer.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
5
  #
6
-
6
+ # Loading the gem "tracer" will cause it to extend IRB commands with:
7
+ # https://github.com/ruby/tracer/blob/v0.2.2/lib/tracer/irb.rb
7
8
  begin
8
9
  require "tracer"
9
10
  rescue LoadError
10
11
  $stderr.puts "Tracer extension of IRB is enabled but tracer gem wasn't found."
11
- module IRB
12
- class Context
13
- def use_tracer=(opt)
14
- # do nothing
15
- end
16
- end
17
- end
18
12
  return # This is about to disable loading below
19
13
  end
20
14
 
21
15
  module IRB
16
+ class CallTracer < ::CallTracer
17
+ IRB_DIR = File.expand_path('../..', __dir__)
22
18
 
23
- # initialize tracing function
24
- def IRB.initialize_tracer
25
- Tracer.verbose = false
26
- Tracer.add_filter {
27
- |event, file, line, id, binding, *rests|
28
- /^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
29
- File::basename(file) != "irb.rb"
30
- }
31
- end
32
-
33
- class Context
34
- # Whether Tracer is used when evaluating statements in this context.
35
- #
36
- # See +lib/tracer.rb+ for more information.
37
- attr_reader :use_tracer
38
- alias use_tracer? use_tracer
39
-
40
- # Sets whether or not to use the Tracer library when evaluating statements
41
- # in this context.
42
- #
43
- # See +lib/tracer.rb+ for more information.
44
- def use_tracer=(opt)
45
- if opt
46
- Tracer.set_get_line_procs(@irb_path) {
47
- |line_no, *rests|
48
- @io.line(line_no)
49
- }
50
- elsif !opt && @use_tracer
51
- Tracer.off
52
- end
53
- @use_tracer=opt
19
+ def skip?(tp)
20
+ super || tp.path.match?(IRB_DIR) || tp.path.match?('<internal:prelude>')
54
21
  end
55
22
  end
56
-
57
23
  class WorkSpace
58
24
  alias __evaluate__ evaluate
59
25
  # Evaluate the context of this workspace and use the Tracer library to
60
26
  # output the exact lines of code are being executed in chronological order.
61
27
  #
62
- # See +lib/tracer.rb+ for more information.
63
- def evaluate(context, statements, file = nil, line = nil)
64
- if context.use_tracer? && file != nil && line != nil
65
- Tracer.on
66
- begin
28
+ # See https://github.com/ruby/tracer for more information.
29
+ def evaluate(statements, file = __FILE__, line = __LINE__)
30
+ if IRB.conf[:USE_TRACER] == true
31
+ CallTracer.new(colorize: Color.colorable?).start do
67
32
  __evaluate__(statements, file, line)
68
- ensure
69
- Tracer.off
70
33
  end
71
34
  else
72
- __evaluate__(statements, file || __FILE__, line || __LINE__)
35
+ __evaluate__(statements, file, line)
73
36
  end
74
37
  end
75
38
  end
76
-
77
- IRB.initialize_tracer
78
39
  end
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # use-loader.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
5
  #
6
6
 
7
- require_relative "../cmd/load"
7
+ require_relative "../command/load"
8
8
  require_relative "loader"
9
9
 
10
10
  class Object
@@ -17,12 +17,12 @@ module IRB
17
17
  remove_method :irb_load if method_defined?(:irb_load)
18
18
  # Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
19
19
  def irb_load(*opts, &b)
20
- ExtendCommand::Load.execute(irb_context, *opts, &b)
20
+ Command::Load.execute(irb_context, *opts, &b)
21
21
  end
22
22
  remove_method :irb_require if method_defined?(:irb_require)
23
23
  # Loads the given file similarly to Kernel#require
24
24
  def irb_require(*opts, &b)
25
- ExtendCommand::Require.execute(irb_context, *opts, &b)
25
+ Command::Require.execute(irb_context, *opts, &b)
26
26
  end
27
27
  end
28
28
 
@@ -49,14 +49,12 @@ module IRB
49
49
  if IRB.conf[:USE_LOADER] != opt
50
50
  IRB.conf[:USE_LOADER] = opt
51
51
  if opt
52
- if !$".include?("irb/cmd/load")
53
- end
54
- (class<<@workspace.main;self;end).instance_eval {
52
+ (class<<workspace.main;self;end).instance_eval {
55
53
  alias_method :load, :irb_load
56
54
  alias_method :require, :irb_require
57
55
  }
58
56
  else
59
- (class<<@workspace.main;self;end).instance_eval {
57
+ (class<<workspace.main;self;end).instance_eval {
60
58
  alias_method :load, :__original__load__IRB_use_loader__
61
59
  alias_method :require, :__original__require__IRB_use_loader__
62
60
  }
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # push-ws.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -6,21 +6,6 @@
6
6
 
7
7
  module IRB # :nodoc:
8
8
  class Context
9
-
10
- # Size of the current WorkSpace stack
11
- def irb_level
12
- workspace_stack.size
13
- end
14
-
15
- # WorkSpaces in the current stack
16
- def workspaces
17
- if defined? @workspaces
18
- @workspaces
19
- else
20
- @workspaces = []
21
- end
22
- end
23
-
24
9
  # Creates a new workspace with the given object or binding, and appends it
25
10
  # onto the current #workspaces stack.
26
11
  #
@@ -28,20 +13,16 @@ module IRB # :nodoc:
28
13
  # information.
29
14
  def push_workspace(*_main)
30
15
  if _main.empty?
31
- if workspaces.empty?
32
- print "No other workspace\n"
33
- return nil
16
+ if @workspace_stack.size > 1
17
+ # swap the top two workspaces
18
+ previous_workspace, current_workspace = @workspace_stack.pop(2)
19
+ @workspace_stack.push current_workspace, previous_workspace
20
+ end
21
+ else
22
+ @workspace_stack.push WorkSpace.new(workspace.binding, _main[0])
23
+ if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
24
+ main.extend ExtendCommandBundle
34
25
  end
35
- ws = workspaces.pop
36
- workspaces.push @workspace
37
- @workspace = ws
38
- return workspaces
39
- end
40
-
41
- workspaces.push @workspace
42
- @workspace = WorkSpace.new(@workspace.binding, _main[0])
43
- if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
44
- main.extend ExtendCommandBundle
45
26
  end
46
27
  end
47
28
 
@@ -50,11 +31,7 @@ module IRB # :nodoc:
50
31
  #
51
32
  # Also, see #push_workspace.
52
33
  def pop_workspace
53
- if workspaces.empty?
54
- print "workspace stack empty\n"
55
- return
56
- end
57
- @workspace = workspaces.pop
34
+ @workspace_stack.pop if @workspace_stack.size > 1
58
35
  end
59
36
  end
60
37
  end
data/lib/irb/frame.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # frame.rb -
4
4
  # by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
data/lib/irb/help.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/help.rb - print usage module
4
4
  # by Keiju ISHITSUKA(keiju@ishitsuka.com)
data/lib/irb/history.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "pathname"
2
+
1
3
  module IRB
2
4
  module HistorySavingAbility # :nodoc:
3
5
  def support_history_saving?
@@ -5,7 +7,7 @@ module IRB
5
7
  end
6
8
 
7
9
  def reset_history_counter
8
- @loaded_history_lines = self.class::HISTORY.size if defined? @loaded_history_lines
10
+ @loaded_history_lines = self.class::HISTORY.size
9
11
  end
10
12
 
11
13
  def load_history
@@ -14,7 +16,7 @@ module IRB
14
16
  if history_file = IRB.conf[:HISTORY_FILE]
15
17
  history_file = File.expand_path(history_file)
16
18
  end
17
- history_file = IRB.rc_file("_history") unless history_file
19
+ history_file = IRB.rc_files("_history").first unless history_file
18
20
  if File.exist?(history_file)
19
21
  File.open(history_file, "r:#{IRB.conf[:LC_MESSAGES].encoding}") do |f|
20
22
  f.each { |l|
@@ -39,7 +41,7 @@ module IRB
39
41
  if history_file = IRB.conf[:HISTORY_FILE]
40
42
  history_file = File.expand_path(history_file)
41
43
  end
42
- history_file = IRB.rc_file("_history") unless history_file
44
+ history_file = IRB.rc_files("_history").first unless history_file
43
45
 
44
46
  # Change the permission of a file that already exists[BUG #7694]
45
47
  begin
@@ -59,13 +61,19 @@ module IRB
59
61
  append_history = true
60
62
  end
61
63
 
64
+ pathname = Pathname.new(history_file)
65
+ unless Dir.exist?(pathname.dirname)
66
+ warn "Warning: The directory to save IRB's history file does not exist. Please double check `IRB.conf[:HISTORY_FILE]`'s value."
67
+ return
68
+ end
69
+
62
70
  File.open(history_file, (append_history ? 'a' : 'w'), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f|
63
71
  hist = history.map{ |l| l.scrub.split("\n").join("\\\n") }
64
72
  unless append_history
65
73
  begin
66
74
  hist = hist.last(num) if hist.size > num and num > 0
67
75
  rescue RangeError # bignum too big to convert into `long'
68
- # Do nothing because the bignum should be treated as inifinity
76
+ # Do nothing because the bignum should be treated as infinity
69
77
  end
70
78
  end
71
79
  f.puts(hist)
data/lib/irb/init.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/init.rb - irb initialize module
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -6,6 +6,7 @@
6
6
 
7
7
  module IRB # :nodoc:
8
8
  @CONF = {}
9
+ @INITIALIZED = false
9
10
  # Displays current configuration.
10
11
  #
11
12
  # Modifying the configuration is achieved by sending a message to IRB.conf.
@@ -41,6 +42,10 @@ module IRB # :nodoc:
41
42
  format("irb %s (%s)", @RELEASE_VERSION, @LAST_UPDATE_DATE)
42
43
  end
43
44
 
45
+ def IRB.initialized?
46
+ !!@INITIALIZED
47
+ end
48
+
44
49
  # initialize config
45
50
  def IRB.setup(ap_path, argv: ::ARGV)
46
51
  IRB.init_config(ap_path)
@@ -52,13 +57,11 @@ module IRB # :nodoc:
52
57
  unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
53
58
  fail UndefinedPromptMode, @CONF[:PROMPT_MODE]
54
59
  end
60
+ @INITIALIZED = true
55
61
  end
56
62
 
57
63
  # @CONF default setting
58
64
  def IRB.init_config(ap_path)
59
- # class instance variables
60
- @TRACER_INITIALIZED = false
61
-
62
65
  # default configurations
63
66
  unless ap_path and @CONF[:AP_NAME]
64
67
  ap_path = File.join(File.dirname(File.dirname(__FILE__)), "irb.rb")
@@ -392,33 +395,41 @@ module IRB # :nodoc:
392
395
  # Run the config file
393
396
  def IRB.run_config
394
397
  if @CONF[:RC]
395
- begin
396
- file = rc_file
398
+ rc_files.each do |rc|
397
399
  # Because rc_file always returns `HOME/.irbrc` even if no rc file is present, we can't warn users about missing rc files.
398
400
  # Otherwise, it'd be very noisy.
399
- load file if File.exist?(file)
401
+ load rc if File.exist?(rc)
400
402
  rescue StandardError, ScriptError => e
401
- warn "Error loading RC file '#{file}':\n#{e.full_message(highlight: false)}"
403
+ warn "Error loading RC file '#{rc}':\n#{e.full_message(highlight: false)}"
402
404
  end
403
405
  end
404
406
  end
405
407
 
406
408
  IRBRC_EXT = "rc"
407
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)
408
415
  if !@CONF[:RC_NAME_GENERATOR]
416
+ @CONF[:RC_NAME_GENERATOR] ||= []
417
+ existing_rc_file_generators = []
418
+
409
419
  rc_file_generators do |rcgen|
410
- @CONF[:RC_NAME_GENERATOR] ||= rcgen
411
- if File.exist?(rcgen.call(IRBRC_EXT))
412
- @CONF[:RC_NAME_GENERATOR] = rcgen
413
- break
414
- end
420
+ @CONF[:RC_NAME_GENERATOR] << rcgen
421
+ existing_rc_file_generators << rcgen if File.exist?(rcgen.call(ext))
422
+ end
423
+
424
+ if existing_rc_file_generators.any?
425
+ @CONF[:RC_NAME_GENERATOR] = existing_rc_file_generators
415
426
  end
416
427
  end
417
- case rc_file = @CONF[:RC_NAME_GENERATOR].call(ext)
418
- when String
428
+
429
+ @CONF[:RC_NAME_GENERATOR].map do |rc|
430
+ rc_file = rc.call(ext)
431
+ fail IllegalRCNameGenerator unless rc_file.is_a?(String)
419
432
  rc_file
420
- else
421
- fail IllegalRCNameGenerator
422
433
  end
423
434
  end
424
435
 
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/input-method.rb - input methods used irb
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -20,7 +20,7 @@ module IRB
20
20
  #
21
21
  # See IO#gets for more information.
22
22
  def gets
23
- fail NotImplementedError, "gets"
23
+ fail NotImplementedError
24
24
  end
25
25
  public :gets
26
26
 
@@ -44,6 +44,10 @@ module IRB
44
44
  false
45
45
  end
46
46
 
47
+ def prompting?
48
+ false
49
+ end
50
+
47
51
  # For debug message
48
52
  def inspect
49
53
  'Abstract InputMethod'
@@ -91,6 +95,10 @@ module IRB
91
95
  true
92
96
  end
93
97
 
98
+ def prompting?
99
+ STDIN.tty?
100
+ end
101
+
94
102
  # Returns the current line number for #io.
95
103
  #
96
104
  # #line counts the number of times #gets is called.
@@ -220,6 +228,10 @@ module IRB
220
228
  @eof
221
229
  end
222
230
 
231
+ def prompting?
232
+ true
233
+ end
234
+
223
235
  # For debug message
224
236
  def inspect
225
237
  readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
@@ -467,6 +479,10 @@ module IRB
467
479
  @eof
468
480
  end
469
481
 
482
+ def prompting?
483
+ true
484
+ end
485
+
470
486
  # For debug message
471
487
  def inspect
472
488
  config = Reline::Config.new
data/lib/irb/inspector.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/inspector.rb - inspect methods
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -46,7 +46,7 @@ module IRB # :nodoc:
46
46
  # Determines the inspector to use where +inspector+ is one of the keys passed
47
47
  # during inspector definition.
48
48
  def self.keys_with_inspector(inspector)
49
- INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
49
+ INSPECTORS.select{|k, v| v == inspector}.collect{|k, v| k}
50
50
  end
51
51
 
52
52
  # Example
@@ -113,7 +113,7 @@ module IRB # :nodoc:
113
113
  Color.colorize_code(v.inspect, colorable: Color.colorable? && Color.inspect_colorable?(v))
114
114
  }
115
115
  Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require_relative "color_printer"}){|v|
116
- IRB::ColorPrinter.pp(v, '').chomp
116
+ IRB::ColorPrinter.pp(v, +'').chomp
117
117
  }
118
118
  Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
119
119
  begin
data/lib/irb/lc/error.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/lc/error.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -12,11 +12,6 @@ module IRB
12
12
  super("Unrecognized switch: #{val}")
13
13
  end
14
14
  end
15
- class NotImplementedError < StandardError
16
- def initialize(val)
17
- super("Need to define `#{val}'")
18
- end
19
- end
20
15
  class CantReturnToNormalMode < StandardError
21
16
  def initialize
22
17
  super("Can't return to normal mode.")
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/lc/ja/error.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -12,11 +12,6 @@ module IRB
12
12
  super("スイッチ(#{val})が分りません")
13
13
  end
14
14
  end
15
- class NotImplementedError < StandardError
16
- def initialize(val)
17
- super("`#{val}'の定義が必要です")
18
- end
19
- end
20
15
  class CantReturnToNormalMode < StandardError
21
16
  def initialize
22
17
  super("Normalモードに戻れません.")
data/lib/irb/locale.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/locale.rb - internationalization module
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -94,7 +94,7 @@ module IRB # :nodoc:
94
94
  end
95
95
  end
96
96
 
97
- def find(file , paths = $:)
97
+ def find(file, paths = $:)
98
98
  dir = File.dirname(file)
99
99
  dir = "" if dir == "."
100
100
  base = File.basename(file)
@@ -12,6 +12,8 @@ module IRB
12
12
  skip = false
13
13
  last_tok, state, args = opens.last
14
14
  case state
15
+ when :in_alias_undef
16
+ skip = t.event == :on_kw
15
17
  when :in_unquoted_symbol
16
18
  unless IGNORE_TOKENS.include?(t.event)
17
19
  opens.pop
@@ -61,17 +63,17 @@ module IRB
61
63
  if args.include?(:arg)
62
64
  case t.event
63
65
  when :on_nl, :on_semicolon
64
- # def recever.f;
66
+ # def receiver.f;
65
67
  body = :normal
66
68
  when :on_lparen
67
- # def recever.f()
69
+ # def receiver.f()
68
70
  next_args << :eq
69
71
  else
70
72
  if t.event == :on_op && t.tok == '='
71
73
  # def receiver.f =
72
74
  body = :oneliner
73
75
  else
74
- # def recever.f arg
76
+ # def receiver.f arg
75
77
  next_args << :arg_without_paren
76
78
  end
77
79
  end
@@ -130,6 +132,10 @@ module IRB
130
132
  opens.pop
131
133
  opens << [t, nil]
132
134
  end
135
+ when 'alias'
136
+ opens << [t, :in_alias_undef, 2]
137
+ when 'undef'
138
+ opens << [t, :in_alias_undef, 1]
133
139
  when 'elsif', 'else', 'when'
134
140
  opens.pop
135
141
  opens << [t, nil]
@@ -174,6 +180,10 @@ module IRB
174
180
  pending_heredocs.reverse_each { |t| opens << [t, nil] }
175
181
  pending_heredocs = []
176
182
  end
183
+ if opens.last && opens.last[1] == :in_alias_undef && !IGNORE_TOKENS.include?(t.event) && t.event != :on_heredoc_end
184
+ tok, state, arg = opens.pop
185
+ opens << [tok, state, arg - 1] if arg >= 1
186
+ end
177
187
  yield t, opens if block_given?
178
188
  end
179
189
  opens.map(&:first) + pending_heredocs.reverse
data/lib/irb/notifier.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # notifier.rb - output methods used by irb
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # output-method.rb - output methods used by irb
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -9,16 +9,10 @@ module IRB
9
9
  # IRB::Notifier. You can define your own output method to use with Irb.new,
10
10
  # or Context.new
11
11
  class OutputMethod
12
- class NotImplementedError < StandardError
13
- def initialize(val)
14
- super("Need to define `#{val}'")
15
- end
16
- end
17
-
18
12
  # Open this method to implement your own output method, raises a
19
13
  # NotImplementedError if you don't define #print in your own class.
20
14
  def print(*opts)
21
- raise NotImplementedError, "print"
15
+ raise NotImplementedError
22
16
  end
23
17
 
24
18
  # Prints the given +opts+, with a newline delimiter.
data/lib/irb/ruby-lex.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/ruby-lex.rb - ruby lexcal analyzer
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -290,7 +290,7 @@ module IRB
290
290
  when :on_embdoc_beg
291
291
  indent_level = 0
292
292
  else
293
- indent_level += 1
293
+ indent_level += 1 unless t.tok == 'alias' || t.tok == 'undef'
294
294
  end
295
295
  end
296
296
  indent_level