diff options
author | Stan Lo <stan001212@gmail.com> | 2023-01-12 11:49:12 +0000 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-01-12 11:49:16 +0000 |
commit | 207f8d0027d679780d4f3962c305d36885feb652 (patch) | |
tree | a54ee6eaeb2f185d6780a8d526a2dfc1856f898d /lib/irb/extend-command.rb | |
parent | 3faecaaa60f9639081f1c4ec26e279cc118cbbea (diff) |
[ruby/irb] Avoid calling private methods on the main object
(https://github.com/ruby/irb/pull/498)
When the main object is frozen, `IRB` wraps a `SimpleDelegator` around it.
But because `SimpleDelegator` doesn't delegate private methods, methods like
`require_relative` or `const_get` would cause error, which are needed for
lazily loading commands.
This commit works around this limitation by avoiding those private method calls
when setting up command execution.
Diffstat (limited to 'lib/irb/extend-command.rb')
-rw-r--r-- | lib/irb/extend-command.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index 6446c48ef8..5020b1e5cd 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -259,8 +259,8 @@ module IRB # :nodoc: 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 @@ module IRB # :nodoc: 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 @@ module IRB # :nodoc: 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 |