[ruby/irb] Remove internal-only methods from Command::Base

(https://github.com/ruby/irb/pull/922)

* Remove internal-only methods from Command::Base

Command#ruby_args and Command#unwrap_string_literal are used for default command's argument backward compatibility.
Moved these methods to another module to avoid being used from custom commands.

* Update lib/irb/command/edit.rb

---------

https://github.com/ruby/irb/commit/7405a841e8

Co-authored-by: Stan Lo <stan001212@gmail.com>
This commit is contained in:
tomoya ishida 2024-04-18 03:36:25 +09:00 коммит произвёл git
Родитель 98c84ef42c
Коммит ca764062b0
10 изменённых файлов: 41 добавлений и 19 удалений

Просмотреть файл

@ -50,25 +50,6 @@ module IRB
attr_reader :irb_context
def unwrap_string_literal(str)
return if str.empty?
sexp = Ripper.sexp(str)
if sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
@irb_context.workspace.binding.eval(str).to_s
else
str
end
end
def ruby_args(arg)
# Use throw and catch to handle arg that includes `;`
# For example: "1, kw: (2; 3); 4" will be parsed to [[1], { kw: 3 }]
catch(:EXTRACT_RUBY_ARGS) do
@irb_context.workspace.binding.eval "IRB::Command.extract_ruby_args #{arg}"
end || [[], {}]
end
def execute(arg)
#nop
end

Просмотреть файл

@ -8,6 +8,8 @@ module IRB
module Command
class Edit < Base
include RubyArgsExtractor
category "Misc"
description 'Open a file or source location.'
help_message <<~HELP_MESSAGE

Просмотреть файл

@ -0,0 +1,27 @@
# frozen_string_literal: true
module IRB
module Command
# Internal use only, for default command's backward compatibility.
module RubyArgsExtractor # :nodoc:
def unwrap_string_literal(str)
return if str.empty?
sexp = Ripper.sexp(str)
if sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
@irb_context.workspace.binding.eval(str).to_s
else
str
end
end
def ruby_args(arg)
# Use throw and catch to handle arg that includes `;`
# For example: "1, kw: (2; 3); 4" will be parsed to [[1], { kw: 3 }]
catch(:EXTRACT_RUBY_ARGS) do
@irb_context.workspace.binding.eval "IRB::Command.extract_ruby_args #{arg}"
end || [[], {}]
end
end
end
end

Просмотреть файл

@ -10,6 +10,7 @@ module IRB
module Command
class LoaderCommand < Base
include RubyArgsExtractor
include IrbLoader
def raise_cmd_argument_error

Просмотреть файл

@ -11,6 +11,8 @@ module IRB
module Command
class Ls < Base
include RubyArgsExtractor
category "Context"
description "Show methods, constants, and variables."

Просмотреть файл

@ -3,6 +3,8 @@ module IRB
module Command
class Measure < Base
include RubyArgsExtractor
category "Misc"
description "`measure` enables the mode to measure processing time. `measure :off` disables it."

Просмотреть файл

@ -3,6 +3,8 @@
module IRB
module Command
class ShowDoc < Base
include RubyArgsExtractor
category "Context"
description "Look up documentation with RI."

Просмотреть файл

@ -7,6 +7,8 @@ require_relative "../color"
module IRB
module Command
class ShowSource < Base
include RubyArgsExtractor
category "Context"
description "Show the source code of a given method, class/module, or constant."

Просмотреть файл

@ -9,6 +9,8 @@ module IRB
module Command
class MultiIRBCommand < Base
include RubyArgsExtractor
private
def print_deprecated_warning

Просмотреть файл

@ -1,6 +1,7 @@
# frozen_string_literal: true
require_relative "command"
require_relative "command/internal_helpers"
require_relative "command/context"
require_relative "command/exit"
require_relative "command/force_exit"