diff options
author | Jeremy Evans <[email protected]> | 2019-12-01 19:57:06 -0800 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2019-12-11 20:23:53 +0900 |
commit | 0dcd3340fb5f91112ce66c53315eff92b9f10fb7 (patch) | |
tree | 819f79f5c9b93c40272ef6923a3d6f47676f96f2 /lib/forwardable.rb | |
parent | c2f6aa4e4810f8f2aabc35bf4c98ee030ff504b9 (diff) |
[ruby/forwardable] Make def_*_delegator return name of method defined (Fixes #10)
This restores compatibility with previous versions. This behavior
was previously undefined, but it makes sense for the name of the
defined method to be returned.
https://github.com/ruby/forwardable/commit/a52ef3451e
Diffstat (limited to 'lib/forwardable.rb')
-rw-r--r-- | lib/forwardable.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/forwardable.rb b/lib/forwardable.rb index e8333a359e..4cfade470a 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -160,6 +160,7 @@ module Forwardable # +accessor.method+. +accessor+ should be a method name, instance # variable name, or constant name. Use the full path to the # constant if providing the constant name. + # Returns the name of the method defined. # # class MyQueue # CONST = 1 @@ -184,8 +185,9 @@ module Forwardable # If it's not a class or module, it's an instance mod = Module === self ? self : singleton_class - mod.module_eval(&gen) + ret = mod.module_eval(&gen) mod.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' + ret end alias delegate instance_delegate @@ -299,11 +301,13 @@ module SingleForwardable # Defines a method _method_ which delegates to _accessor_ (i.e. it calls # the method of the same name in _accessor_). If _new_name_ is # provided, it is used as the name for the delegate method. + # Returns the name of the method defined. def def_single_delegator(accessor, method, ali = method) gen = Forwardable._delegator_method(self, accessor, method, ali) - instance_eval(&gen) + ret = instance_eval(&gen) singleton_class.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' + ret end alias delegate single_delegate |