summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 05:22:55 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 05:22:55 +0000
commit4c81b1095373559789c1c0333ba6b780f7e0153e (patch)
tree9532d73cf5acca444805fc89ca75d4d287edeba0 /lib
parent1cca2abf3525cfc2c899f4a0ece2b5c902c45420 (diff)
merge revision(s) 53381,53382,53511,53512: [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. * lib/forwardable.rb: Convert given accessors to String. r53381 changed to accept only Symbol or String for accessors, but there are several rubygems that pass classes (e.g. Array, Hash, ...) as accessors. Prior r53381, it was accepted because Class#to_s returns its class name. After r53381 given accessors are checked with define_method, but it accepts only Symbol or String, otherwise raises TypeError. def_delegator Foo, :some_method This change is to revert unwanted incompatibility. But this behavior may change in the future. This change is to revert unexpected incompatibility. But this behavior git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/forwardable.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index ecc5f03843..602cd8b815 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -177,6 +177,11 @@ module Forwardable
# q.push 23 #=> NoMethodError
#
def def_instance_delegator(accessor, method, ali = method)
+ accessor = accessor.to_s
+ if method_defined?(accessor) || private_method_defined?(accessor)
+ accessor = "#{accessor}()"
+ end
+
line_no = __LINE__; str = %{
def #{ali}(*args, &block)
begin
@@ -269,7 +274,12 @@ 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 = %{
+ accessor = accessor.to_s
+ 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)
@@ -280,7 +290,7 @@ module SingleForwardable
end
}
- instance_eval(str, __FILE__, __LINE__)
+ instance_eval(str, __FILE__, line_no)
end
alias delegate single_delegate