summaryrefslogtreecommitdiff
path: root/lib/irb/extend-command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irb/extend-command.rb')
-rw-r--r--lib/irb/extend-command.rb35
1 files changed, 7 insertions, 28 deletions
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb
index 8e985274b1..1a252bb42a 100644
--- a/lib/irb/extend-command.rb
+++ b/lib/irb/extend-command.rb
@@ -246,7 +246,7 @@ module IRB # :nodoc:
#
# The optional +load_file+ parameter will be required within the method
# definition.
- def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
+ def self.def_extend_command(cmd_name, cmd_class, load_file, *aliases)
case cmd_class
when Symbol
cmd_class = cmd_class.id2name
@@ -255,33 +255,12 @@ module IRB # :nodoc:
cmd_class = cmd_class.name
end
- if load_file
- line = __LINE__; eval %[
- def #{cmd_name}(*opts, **kwargs, &b)
- 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"
- args = args.join(", ")
- line = __LINE__; eval %[
- unless singleton_class.class_variable_defined?(:@@#{cmd_name}_)
- singleton_class.class_variable_set(:@@#{cmd_name}_, true)
- def self.#{cmd_name}_(\#{args})
- ::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
- end
- end
- ], nil, __FILE__, line
- __send__ :#{cmd_name}_, *opts, **kwargs, &b
- end
- ], nil, __FILE__, line
- else
- line = __LINE__; eval %[
- def #{cmd_name}(*opts, &b)
- ::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
- end
- ], nil, __FILE__, line
- end
+ line = __LINE__; eval %[
+ def #{cmd_name}(*opts, **kwargs, &b)
+ Kernel.require_relative "#{load_file}"
+ ::IRB::ExtendCommand::#{cmd_class}.execute(irb_context, *opts, **kwargs, &b)
+ end
+ ], nil, __FILE__, line
for ali, flag in aliases
@ALIASES.push [ali, cmd_name, flag]