diff options
author | Stan Lo <[email protected]> | 2023-04-05 22:40:34 +0100 |
---|---|---|
committer | git <[email protected]> | 2023-04-05 21:40:40 +0000 |
commit | 2f8e5c80e65a14b3a9298b6cae7ee7fc53890540 (patch) | |
tree | ca1b18b39c4a0d95017361207b635d71a173a639 /lib | |
parent | 1587494b0b5f64a9976dcf0bd94dfe98123c2c27 (diff) |
[ruby/irb] Drop Ruby 2.6 support
(https://github.com/ruby/irb/pull/555)
* Remove all Ruby 2.6 support
* Drop Ruby 2.6 specific testing conditions
* Only run Ruby 2.7+ on CI
* Bump Ruby requirement to 2.7+
https://github.com/ruby/irb/commit/3f714b616c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/irb.rb | 1 | ||||
-rw-r--r-- | lib/irb/cmd/nop.rb | 19 | ||||
-rw-r--r-- | lib/irb/cmd/show_source.rb | 2 | ||||
-rw-r--r-- | lib/irb/color.rb | 12 | ||||
-rw-r--r-- | lib/irb/completion.rb | 10 | ||||
-rw-r--r-- | lib/irb/ext/loader.rb | 25 | ||||
-rw-r--r-- | lib/irb/extend-command.rb | 7 | ||||
-rw-r--r-- | lib/irb/inspector.rb | 3 | ||||
-rw-r--r-- | lib/irb/irb.gemspec | 2 | ||||
-rw-r--r-- | lib/irb/ruby-lex.rb | 20 |
10 files changed, 24 insertions, 77 deletions
diff --git a/lib/irb.rb b/lib/irb.rb index f9f39a1def..13fbbbad29 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -560,7 +560,6 @@ module IRB @scanner.each_top_level_statement do |line, line_no| signal_status(:IN_EVAL) do begin - line.untaint if RUBY_VERSION < '2.7' if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty? IRB.set_measure_callback end diff --git a/lib/irb/cmd/nop.rb b/lib/irb/cmd/nop.rb index 2e112d1705..fc6231f0a7 100644 --- a/lib/irb/cmd/nop.rb +++ b/lib/irb/cmd/nop.rb @@ -30,20 +30,11 @@ module IRB end end - if RUBY_VERSION >= "2.7.0" - def self.execute(conf, *opts, **kwargs, &block) - command = new(conf) - command.execute(*opts, **kwargs, &block) - rescue CommandArgumentError => e - puts e.message - end - else - def self.execute(conf, *opts, &block) - command = new(conf) - command.execute(*opts, &block) - rescue CommandArgumentError => e - puts e.message - end + def self.execute(conf, *opts, **kwargs, &block) + command = new(conf) + command.execute(*opts, **kwargs, &block) + rescue CommandArgumentError => e + puts e.message end def initialize(conf) diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb index eb21533b56..f4925a8311 100644 --- a/lib/irb/cmd/show_source.rb +++ b/lib/irb/cmd/show_source.rb @@ -27,7 +27,7 @@ module IRB when /\A[A-Z]\w*(::[A-Z]\w*)*\z/ # Const::Name eval(str, irb_context.workspace.binding) # trigger autoload base = irb_context.workspace.binding.receiver.yield_self { |r| r.is_a?(Module) ? r : Object } - file, line = base.const_source_location(str) if base.respond_to?(:const_source_location) # Ruby 2.7+ + file, line = base.const_source_location(str) when /\A(?<owner>[A-Z]\w*(::[A-Z]\w*)*)#(?<method>[^ :.]+)\z/ # Class#method owner = eval(Regexp.last_match[:owner], irb_context.workspace.binding) method = Regexp.last_match[:method] diff --git a/lib/irb/color.rb b/lib/irb/color.rb index 52d6240910..fa99ed6fd6 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -197,15 +197,9 @@ module IRB # :nodoc: end end - if lexer.respond_to?(:scan) # Ruby 2.7+ - lexer.scan.each do |elem| - next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message - on_scan.call(elem) - end - else - lexer.parse.sort_by(&:pos).each do |elem| - on_scan.call(elem) - end + lexer.scan.each do |elem| + next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message + on_scan.call(elem) end # yield uncolorable DATA section yield(nil, inner_code.byteslice(byte_pos...inner_code.bytesize), nil) if byte_pos < inner_code.bytesize diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 6a7e04264a..84f4c4e35a 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -58,19 +58,11 @@ module IRB BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{(" - def self.absolute_path?(p) # TODO Remove this method after 2.6 EOL. - if File.respond_to?(:absolute_path?) - File.absolute_path?(p) - else - File.absolute_path(p) == p - end - end - GEM_PATHS = if defined?(Gem::Specification) Gem::Specification.latest_specs(true).map { |s| s.require_paths.map { |p| - if absolute_path?(p) + if File.absolute_path?(p) p else File.join(s.full_gem_path, p) diff --git a/lib/irb/ext/loader.rb b/lib/irb/ext/loader.rb index 0a599ee802..1ab8a4e322 100644 --- a/lib/irb/ext/loader.rb +++ b/lib/irb/ext/loader.rb @@ -24,31 +24,8 @@ module IRB # :nodoc: load_file(path, priv) end - if File.respond_to?(:absolute_path?) - def absolute_path?(path) - File.absolute_path?(path) - end - else - separator = - if File::ALT_SEPARATOR - "[#{Regexp.quote(File::SEPARATOR + File::ALT_SEPARATOR)}]" - else - File::SEPARATOR - end - ABSOLUTE_PATH_PATTERN = # :nodoc: - case Dir.pwd - when /\A\w:/, /\A#{separator}{2}/ - /\A(?:\w:|#{separator})#{separator}/ - else - /\A#{separator}/ - end - def absolute_path?(path) - ABSOLUTE_PATH_PATTERN =~ path - end - end - def search_file_from_ruby_path(fn) # :nodoc: - if absolute_path?(fn) + if File.absolute_path?(fn) return fn if File.exist?(fn) return nil end diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index 4018eb13a6..8e985274b1 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -256,13 +256,12 @@ module IRB # :nodoc: end if load_file - kwargs = ", **kwargs" if RUBY_VERSION >= "2.7.0" line = __LINE__; eval %[ - def #{cmd_name}(*opts#{kwargs}, &b) + def #{cmd_name}(*opts, **kwargs, &b) Kernel.require_relative "#{load_file}" arity = ::IRB::ExtendCommand::#{cmd_class}.instance_method(:execute).arity args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s } - args << "*opts#{kwargs}" if arity < 0 + args << "*opts, **kwargs" if arity < 0 args << "&block" args = args.join(", ") line = __LINE__; eval %[ @@ -273,7 +272,7 @@ module IRB # :nodoc: end end ], nil, __FILE__, line - __send__ :#{cmd_name}_, *opts#{kwargs}, &b + __send__ :#{cmd_name}_, *opts, **kwargs, &b end ], nil, __FILE__, line else diff --git a/lib/irb/inspector.rb b/lib/irb/inspector.rb index bdfa282f0d..ee3b19efdc 100644 --- a/lib/irb/inspector.rb +++ b/lib/irb/inspector.rb @@ -98,8 +98,7 @@ module IRB # :nodoc: puts "An error occurred when inspecting the object: #{e.inspect}" begin - # TODO: change this to bind_call when we drop support for Ruby 2.6 - puts "Result of Kernel#inspect: #{KERNEL_INSPECT.bind(v).call}" + puts "Result of Kernel#inspect: #{KERNEL_INSPECT.bind_call(v)}" '' rescue => e puts "An error occurred when running Kernel#inspect: #{e.inspect}" diff --git a/lib/irb/irb.gemspec b/lib/irb/irb.gemspec index 20c187f37f..e62429ca7b 100644 --- a/lib/irb/irb.gemspec +++ b/lib/irb/irb.gemspec @@ -39,7 +39,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.required_ruby_version = Gem::Requirement.new(">= 2.6") + spec.required_ruby_version = Gem::Requirement.new(">= 2.7") spec.add_dependency "reline", ">= 0.3.0" end diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 9e4a7b28fa..a156f3707a 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -148,19 +148,15 @@ class RubyLex compile_with_errors_suppressed(code, line_no: line_no) do |inner_code, line_no| lexer = Ripper::Lexer.new(inner_code, '-', line_no) - if lexer.respond_to?(:scan) # Ruby 2.7+ - lexer.scan.each_with_object([]) do |t, tokens| - next if t.pos.first == 0 - prev_tk = tokens.last - position_overlapped = prev_tk && t.pos[0] == prev_tk.pos[0] && t.pos[1] < prev_tk.pos[1] + prev_tk.tok.bytesize - if position_overlapped - tokens[-1] = t if ERROR_TOKENS.include?(prev_tk.event) && !ERROR_TOKENS.include?(t.event) - else - tokens << t - end + lexer.scan.each_with_object([]) do |t, tokens| + next if t.pos.first == 0 + prev_tk = tokens.last + position_overlapped = prev_tk && t.pos[0] == prev_tk.pos[0] && t.pos[1] < prev_tk.pos[1] + prev_tk.tok.bytesize + if position_overlapped + tokens[-1] = t if ERROR_TOKENS.include?(prev_tk.event) && !ERROR_TOKENS.include?(t.event) + else + tokens << t end - else - lexer.parse.reject { |it| it.pos.first == 0 }.sort_by(&:pos) end end ensure |