def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
public
aliases = [commands_alias, flag], …
Show source
def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
case cmd_class
when Symbol
cmd_class = cmd_class.id2name
when String
when Class
cmd_class = cmd_class.name
end
if load_file
line = __LINE__; eval %[
def #{cmd_name}(*opts, &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" if arity < 0
args << "&block"
args = args.join(", ")
line = __LINE__; eval %[
def #{cmd_name}(\#{args})
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
end
], nil, __FILE__, line
send :
end
], nil, __FILE__, line
else
line = __LINE__; eval %[
def #{cmd_name}(*opts, &b)
ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
end
], nil, __FILE__, line
end
for ali, flag in aliases
@ALIASES.push [ali, cmd_name, flag]
end
end