summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-15 07:22:53 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-15 07:22:53 +0000
commit6fe4aa6ed75908cab04f23a36619d04b19cf3466 (patch)
tree0cb17e470be100835774808e1a31fb8c7e20b10b /lib
parenta2edc111a77f63740d338ba64b3a7edb72a1becc (diff)
merge revision(s) 53381: [Backport #11916]
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@54595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/forwardable.rb12
1 files changed, 10 insertions, 2 deletions
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