diff --git a/ChangeLog b/ChangeLog index 2e2202f6e6..b535efeb4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Dec 30 11:18:42 2015 Elliot Winkler + + * lib/forwardable.rb (def_instance_delegator) fix delegating to + 'args' and 'block', clashing with local variables in generated + methods. [ruby-core:72579] [Bug #11916] + + * lib/forwardable.rb (def_single_delegator): ditto. + Wed Dec 30 09:58:56 2015 Nobuyoshi Nakada * object.c (rb_class_inherited_p): search the corresponding diff --git a/lib/forwardable.rb b/lib/forwardable.rb index cd15eeab0c..f27437af82 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -178,6 +178,10 @@ module Forwardable # q.push 23 #=> NoMethodError # def def_instance_delegator(accessor, method, ali = method) + if method_defined?(accessor) || private_method_defined?(accessor) + accessor = "#{accessor}()" + end + line_no = __LINE__; str = %{ def #{ali}(*args, &block) begin @@ -270,7 +274,11 @@ module SingleForwardable # the method of the same name in _accessor_). If _new_name_ is # provided, it is used as the name for the delegate method. def def_single_delegator(accessor, method, ali = method) - str = %{ + if method_defined?(accessor) || private_method_defined?(accessor) + accessor = "#{accessor}()" + end + + line_no = __LINE__; str = %{ def #{ali}(*args, &block) begin #{accessor}.__send__(:#{method}, *args, &block) @@ -281,7 +289,7 @@ module SingleForwardable end } - instance_eval(str, __FILE__, __LINE__) + instance_eval(str, __FILE__, line_no) end alias delegate single_delegate