aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStan Lo <stan.lo@shopify.com>2022-12-07 23:29:55 +0000
committergit <svn-admin@ruby-lang.org>2022-12-07 23:30:00 +0000
commita2d3f5606a241999feda113f7331cf1a637bcaf0 (patch)
treed63c9844031404af6c8bf87378a317d1b07e4ac6
parent30c76f4d0d1b090a2ac4885f10f31d59d9c243df (diff)
downloadruby-a2d3f5606a241999feda113f7331cf1a637bcaf0.tar.gz
[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>
-rw-r--r--lib/irb/cmd/subirb.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/irb/cmd/subirb.rb b/lib/irb/cmd/subirb.rb
index b322aadc53..4d113c5bd7 100644
--- a/lib/irb/cmd/subirb.rb
+++ b/lib/irb/cmd/subirb.rb
@@ -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