1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

irb: Define extension command only on the given object

Not to interfer in class variables.
This commit is contained in:
Nobuyoshi Nakada 2020-12-20 18:25:39 +09:00
parent 0fad9a9e30
commit feea436feb
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 5 additions and 3 deletions

View file

@ -177,8 +177,8 @@ module IRB # :nodoc:
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

View file

@ -170,13 +170,15 @@ module TestIRB
"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