Skip to content

Commit

Permalink
Support Ruby 2.6 and below
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 19, 2021
1 parent 5749bda commit 66809bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions lib/irb/cmd/nop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lib/irb/extend-command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %[
Expand All @@ -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
Expand Down

0 comments on commit 66809bd

Please sign in to comment.