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:
parent
0fad9a9e30
commit
feea436feb
2 changed files with 5 additions and 3 deletions
|
@ -177,8 +177,8 @@ module IRB # :nodoc:
|
||||||
args << "&block"
|
args << "&block"
|
||||||
args = args.join(", ")
|
args = args.join(", ")
|
||||||
line = __LINE__; eval %[
|
line = __LINE__; eval %[
|
||||||
unless self.class.class_variable_defined?(:@@#{cmd_name}_)
|
unless self.singleton_class.class_variable_defined?(:@@#{cmd_name}_)
|
||||||
self.class.class_variable_set(:@@#{cmd_name}_, true)
|
self.singleton_class.class_variable_set(:@@#{cmd_name}_, true)
|
||||||
def #{cmd_name}_(\#{args})
|
def #{cmd_name}_(\#{args})
|
||||||
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
|
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
|
||||||
end
|
end
|
||||||
|
|
|
@ -170,13 +170,15 @@ module TestIRB
|
||||||
"measure :off\n",
|
"measure :off\n",
|
||||||
"3\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"
|
irb.context.return_format = "=> %s\n"
|
||||||
out, err = capture_output do
|
out, err = capture_output do
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
end
|
end
|
||||||
assert_empty err
|
assert_empty err
|
||||||
assert_match(/\A=> 3\nTIME is added\.\n=> nil\nprocessing time: .+\n=> 3\n=> nil\n=> 3\n/, out)
|
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
|
end
|
||||||
|
|
||||||
def test_measure_enabled_by_rc
|
def test_measure_enabled_by_rc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue