diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index 6446c48ef..5020b1e5c 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -259,8 +259,8 @@ def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases) kwargs = ", **kwargs" if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.7.0" line = __LINE__; eval %[ def #{cmd_name}(*opts#{kwargs}, &b) - require_relative "#{load_file}" - arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity + Kernel.require_relative "#{load_file}" + arity = ::IRB::ExtendCommand::#{cmd_class}.instance_method(:execute).arity args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s } args << "*opts#{kwargs}" if arity < 0 args << "&block" @@ -269,7 +269,7 @@ def #{cmd_name}(*opts#{kwargs}, &b) unless singleton_class.class_variable_defined?(:@@#{cmd_name}_) singleton_class.class_variable_set(:@@#{cmd_name}_, true) def self.#{cmd_name}_(\#{args}) - ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) + ::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) end end ], nil, __FILE__, line @@ -279,7 +279,7 @@ def self.#{cmd_name}_(\#{args}) else line = __LINE__; eval %[ def #{cmd_name}(*opts, &b) - ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b) + ::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b) end ], nil, __FILE__, line end diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index b909de56e..900d9d898 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -49,6 +49,19 @@ def execute_lines(*lines, conf: {}, main: self, irb_path: nil) end end + class FrozenObjectTest < CommandTestCase + def test_calling_command_on_a_frozen_main + main = Object.new.freeze + + out, err = execute_lines( + "irb_info", + main: main + ) + assert_empty err + assert_match(/RUBY_PLATFORM/, out) + end + end + class CommnadAliasTest < CommandTestCase def test_vars_with_aliases @foo = "foo"