diff options
-rw-r--r-- | lib/forwardable.rb | 8 | ||||
-rw-r--r-- | test/test_forwardable.rb | 8 |
2 files changed, 12 insertions, 4 deletions
@@ -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. # # 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) mod.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' 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. def def_single_delegator(accessor, method, ali = method) gen = Forwardable._delegator_method(self, accessor, method, ali) - instance_eval(&gen) singleton_class.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' end alias delegate single_delegate @@ -24,11 +24,13 @@ class TestForwardable < Test::Unit::TestCase def test_def_instance_delegator %i[def_delegator def_instance_delegator].each do |m| cls = forwardable_class do - __send__ m, :@receiver, :delegated1 end assert_same RETURNED1, cls.new.delegated1 end end @@ -185,11 +187,13 @@ class TestForwardable < Test::Unit::TestCase def test_class_single_delegator %i[def_delegator def_single_delegator].each do |m| cls = single_forwardable_class do - __send__ m, :@receiver, :delegated1 end assert_same RETURNED1, cls.delegated1 end end |