[ruby/irb] Lazily load the multi-irb extension

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

* Lazily load the multi-irb extension

We now have plan to implement a command that prints all commands'
information, which will need to load all command files without actually
running them.

But because the `multi-irb` extension patches IRB's top-level methods,
loading it would cause unintentional side-effects.

So this commit moves related requires into command execution to avoid the problem.

* Make extend_irb_context private

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
This commit is contained in:
Stan Lo 2022-12-07 23:29:55 +00:00 committed by git
parent 30c76f4d0d
commit a2d3f5606a

View File

@ -10,31 +10,44 @@
#
require_relative "nop"
require_relative "../ext/multi-irb"
module IRB
# :stopdoc:
module ExtendCommand
class IrbCommand < Nop
class MultiIRBCommand < Nop
def initialize(conf)
super
extend_irb_context
end
private
def extend_irb_context
# this extension patches IRB context like IRB.CurrentContext
require_relative "../ext/multi-irb"
end
end
class IrbCommand < MultiIRBCommand
def execute(*obj)
IRB.irb(nil, *obj)
end
end
class Jobs < Nop
class Jobs < MultiIRBCommand
def execute
IRB.JobManager
end
end
class Foreground < Nop
class Foreground < MultiIRBCommand
def execute(key)
IRB.JobManager.switch(key)
end
end
class Kill < Nop
class Kill < MultiIRBCommand
def execute(*keys)
IRB.JobManager.kill(*keys)
end