1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/irb/extend-command.rb (def_extend_command): fixed argument

number for negative arity.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-12-05 01:18:28 +00:00
parent 8237d170ee
commit b271ca8c62
2 changed files with 16 additions and 11 deletions

View file

@ -1,3 +1,8 @@
Sat Dec 5 10:18:26 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/irb/extend-command.rb (def_extend_command): fixed argument
number for negative arity.
Fri Dec 4 16:50:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Dec 4 16:50:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (k_def): adjust the location of method definition to the * parse.y (k_def): adjust the location of method definition to the

View file

@ -122,28 +122,28 @@ module IRB
end end
if load_file if load_file
eval %[ line = __LINE__; eval %[
def #{cmd_name}(*opts, &b) def #{cmd_name}(*opts, &b)
require "#{load_file}" require "#{load_file}"
arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity
args = (1..arity.abs).map {|i| "arg" + i.to_s } args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s }
args << "*opts" if arity < 0 args << "*opts" if arity < 0
args << "&block" args << "&block"
args = args.join(", ") args = args.join(", ")
eval %[ line = __LINE__; eval %[
def #{cmd_name}(\#{args}) def #{cmd_name}(\#{args})
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
end end
] ], nil, __FILE__, line
send :#{cmd_name}, *opts, &b send :#{cmd_name}, *opts, &b
end end
] ], nil, __FILE__, line
else else
eval %[ line = __LINE__; eval %[
def #{cmd_name}(*opts, &b) def #{cmd_name}(*opts, &b)
ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b) ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
end end
] ], nil, __FILE__, line
end end
for ali, flag in aliases for ali, flag in aliases
@ -160,7 +160,7 @@ module IRB
(override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or (override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
(override == NO_OVERRIDE) && !respond_to?(to, true) (override == NO_OVERRIDE) && !respond_to?(to, true)
target = self target = self
(class<<self;self;end).instance_eval{ (class << self; self; end).instance_eval{
if target.respond_to?(to, true) && if target.respond_to?(to, true) &&
!target.respond_to?(EXCB.irb_original_method_name(to), true) !target.respond_to?(EXCB.irb_original_method_name(to), true)
alias_method(EXCB.irb_original_method_name(to), to) alias_method(EXCB.irb_original_method_name(to), to)
@ -177,7 +177,7 @@ module IRB
end end
def self.extend_object(obj) def self.extend_object(obj)
unless (class<<obj;ancestors;end).include?(EXCB) unless (class << obj; ancestors; end).include?(EXCB)
super super
for ali, com, flg in @ALIASES for ali, com, flg in @ALIASES
obj.install_alias_method(ali, com, flg) obj.install_alias_method(ali, com, flg)
@ -207,7 +207,7 @@ module IRB
end end
def self.def_extend_command(cmd_name, load_file, *aliases) def self.def_extend_command(cmd_name, load_file, *aliases)
Context.module_eval %[ line = __LINE__; Context.module_eval %[
def #{cmd_name}(*opts, &b) def #{cmd_name}(*opts, &b)
Context.module_eval {remove_method(:#{cmd_name})} Context.module_eval {remove_method(:#{cmd_name})}
require "#{load_file}" require "#{load_file}"
@ -216,7 +216,7 @@ module IRB
for ali in aliases for ali in aliases
alias_method ali, cmd_name alias_method ali, cmd_name
end end
] ], __FILE__, line
end end
CE.install_extend_commands CE.install_extend_commands