mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/forwardable] Make def_{instance,single}_delegators skip :__send__ and :__id__
Previously, __send__ and __id__ were skipped if provided as strings, but not skipped if provided as symbols. Fixes Ruby Bug 8855. https://github.com/ruby/forwardable/commit/2e61c8c66c
This commit is contained in:
parent
b15e0983f7
commit
d00551a7bb
2 changed files with 28 additions and 6 deletions
|
@ -149,9 +149,8 @@ module Forwardable
|
|||
# def_delegator :@records, :map
|
||||
#
|
||||
def def_instance_delegators(accessor, *methods)
|
||||
methods.delete("__send__")
|
||||
methods.delete("__id__")
|
||||
for method in methods
|
||||
methods.each do |method|
|
||||
next if method.to_s == "__send__" || method.to_s == "__id__"
|
||||
def_instance_delegator(accessor, method)
|
||||
end
|
||||
end
|
||||
|
@ -286,9 +285,8 @@ module SingleForwardable
|
|||
# def_delegator :@records, :map
|
||||
#
|
||||
def def_single_delegators(accessor, *methods)
|
||||
methods.delete("__send__")
|
||||
methods.delete("__id__")
|
||||
for method in methods
|
||||
methods.each do |method|
|
||||
next if method.to_s == "__send__" || method.to_s == "__id__"
|
||||
def_single_delegator(accessor, method)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -107,6 +107,18 @@ class TestForwardable < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_def_instance_delegators_send_id
|
||||
%i[def_delegators def_instance_delegators].each do |m|
|
||||
cls = forwardable_class do
|
||||
attr_reader :receiver
|
||||
__send__ m, :@receiver, :__send__, :__id__
|
||||
end
|
||||
|
||||
assert_not_equal cls.new.__id__, cls.new.receiver.__id__
|
||||
assert_not_equal cls.new.__send__(:__id__), cls.new.receiver.__send__(:__id__)
|
||||
end
|
||||
end
|
||||
|
||||
def test_instance_delegate
|
||||
%i[delegate instance_delegate].each do |m|
|
||||
cls = forwardable_class do
|
||||
|
@ -215,6 +227,18 @@ class TestForwardable < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_obj_single_delegators_send_id
|
||||
%i[def_delegators def_single_delegators].each do |m|
|
||||
obj = single_forwardable_object do
|
||||
singleton_class.attr_reader :receiver
|
||||
__send__ m, :@receiver, :__send__, :__id__
|
||||
end
|
||||
|
||||
assert_not_equal obj.__id__, obj.receiver.__id__
|
||||
assert_not_equal obj.__send__(:__id__), obj.receiver.__send__(:__id__)
|
||||
end
|
||||
end
|
||||
|
||||
def test_obj_single_delegate
|
||||
%i[delegate single_delegate].each do |m|
|
||||
obj = single_forwardable_object do
|
||||
|
|
Loading…
Reference in a new issue