[ruby/irb] Refactor ExtendCommand::Nop

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

* Rename conf to irb_context

* Drop Nop#irb method because it's only used by irb/ext/loader.rb

We don't need to expose this method to all command classes, especially
when it's just an alias of `irb_context.irb`.
This commit is contained in:
Stan Lo 2023-06-05 20:12:12 +01:00 committed by git
parent 273b38475e
commit 45ff2f4a89
2 changed files with 6 additions and 8 deletions

View File

@ -30,23 +30,19 @@ module IRB
end end
end end
def self.execute(conf, *opts, **kwargs, &block) def self.execute(irb_context, *opts, **kwargs, &block)
command = new(conf) command = new(irb_context)
command.execute(*opts, **kwargs, &block) command.execute(*opts, **kwargs, &block)
rescue CommandArgumentError => e rescue CommandArgumentError => e
puts e.message puts e.message
end end
def initialize(conf) def initialize(irb_context)
@irb_context = conf @irb_context = irb_context
end end
attr_reader :irb_context attr_reader :irb_context
def irb
@irb_context.irb
end
def execute(*opts) def execute(*opts)
#nop #nop
end end

View File

@ -42,6 +42,7 @@ module IRB # :nodoc:
# #
# See Irb#suspend_input_method for more information. # See Irb#suspend_input_method for more information.
def source_file(path) def source_file(path)
irb = irb_context.irb
irb.suspend_name(path, File.basename(path)) do irb.suspend_name(path, File.basename(path)) do
FileInputMethod.open(path) do |io| FileInputMethod.open(path) do |io|
irb.suspend_input_method(io) do irb.suspend_input_method(io) do
@ -66,6 +67,7 @@ module IRB # :nodoc:
# #
# See Irb#suspend_input_method for more information. # See Irb#suspend_input_method for more information.
def load_file(path, priv = nil) def load_file(path, priv = nil)
irb = irb_context.irb
irb.suspend_name(path, File.basename(path)) do irb.suspend_name(path, File.basename(path)) do
if priv if priv