diff --git a/lib/irb/cmd/nop.rb b/lib/irb/cmd/nop.rb index 76ea6c40a..19c087873 100644 --- a/lib/irb/cmd/nop.rb +++ b/lib/irb/cmd/nop.rb @@ -14,10 +14,16 @@ module IRB module ExtendCommand class Nop - - def self.execute(conf, *opts, **kwargs, &block) - command = new(conf) - command.execute(*opts, **kwargs, &block) + if RUBY_VERSION >= "2.7.0" + def self.execute(conf, *opts, **kwargs, &block) + command = new(conf) + command.execute(*opts, **kwargs, &block) + end + else + def self.execute(conf, *opts, &block) + command = new(conf) + command.execute(*opts, &block) + end end def initialize(conf) diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index ca2b9cf5a..45ef0ec0b 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -174,12 +174,13 @@ def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases) end if load_file + kwargs = ", **kwargs" if RUBY_VERSION >= "2.7.0" line = __LINE__; eval %[ - def #{cmd_name}(*opts, **kwargs, &b) + def #{cmd_name}(*opts#{kwargs}, &b) require "#{load_file}" arity = 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 << "*opts#{kwargs}" if arity < 0 args << "&block" args = args.join(", ") line = __LINE__; eval %[ @@ -190,7 +191,7 @@ def self.#{cmd_name}_(\#{args}) end end ], nil, __FILE__, line - __send__ :#{cmd_name}_, *opts, **kwargs, &b + __send__ :#{cmd_name}_, *opts#{kwargs}, &b end ], nil, __FILE__, line else