ruby-changes:64381
From: Nobuyoshi <ko1@a...>
Date: Sun, 20 Dec 2020 18:32:25 +0900 (JST)
Subject: [ruby-changes:64381] feea436feb (master): irb: Define extension command only on the given object
https://git.ruby-lang.org/ruby.git/commit/?id=feea436feb From feea436febb50eb4265bd985a550e384c606122c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 20 Dec 2020 18:25:39 +0900 Subject: irb: Define extension command only on the given object Not to interfer in class variables. diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index 55e7b3e..02b7869 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -177,8 +177,8 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/extend-command.rb#L177 args << "&block" args = args.join(", ") line = __LINE__; eval %[ - unless self.class.class_variable_defined?(:@@#{cmd_name}_) - self.class.class_variable_set(:@@#{cmd_name}_, true) + unless self.singleton_class.class_variable_defined?(:@@#{cmd_name}_) + self.singleton_class.class_variable_set(:@@#{cmd_name}_, true) def #{cmd_name}_(\#{args}) ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) end diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index 699c9cd..55549d0 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -170,13 +170,15 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_cmd.rb#L170 "measure :off\n", "3\n", ]) - irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) + c = Class.new(Object) + irb = IRB::Irb.new(IRB::WorkSpace.new(c.new), input) irb.context.return_format = "=> %s\n" out, err = capture_output do irb.eval_input end assert_empty err assert_match(/\A=> 3\nTIME is added\.\n=> nil\nprocessing time: .+\n=> 3\n=> nil\n=> 3\n/, out) + assert_empty(c.class_variables) end def test_measure_enabled_by_rc -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/