[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:
parent
30c76f4d0d
commit
a2d3f5606a
@ -10,31 +10,44 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
require_relative "nop"
|
require_relative "nop"
|
||||||
require_relative "../ext/multi-irb"
|
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
|
|
||||||
module ExtendCommand
|
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)
|
def execute(*obj)
|
||||||
IRB.irb(nil, *obj)
|
IRB.irb(nil, *obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Jobs < Nop
|
class Jobs < MultiIRBCommand
|
||||||
def execute
|
def execute
|
||||||
IRB.JobManager
|
IRB.JobManager
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Foreground < Nop
|
class Foreground < MultiIRBCommand
|
||||||
def execute(key)
|
def execute(key)
|
||||||
IRB.JobManager.switch(key)
|
IRB.JobManager.switch(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Kill < Nop
|
class Kill < MultiIRBCommand
|
||||||
def execute(*keys)
|
def execute(*keys)
|
||||||
IRB.JobManager.kill(*keys)
|
IRB.JobManager.kill(*keys)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user