summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2019-06-24 15:07:00 -0700
committerJeremy Evans <[email protected]>2019-07-26 07:35:58 -0700
commit4b7d7d007fa5a06d237be6f379106feea25fca79 ()
treef79ecb64050abbc88d3c1616fa794eda4c668026
parent21ce8b3298bd3b2c8afa7fd747a958e70b55b708 (diff)
Document and add spec for delegating to constants in Forwardable
Fixes [Bug #13142]
-rw-r--r--lib/forwardable.rb10
-rw-r--r--test/test_forwardable.rb11
2 files changed, 19 insertions, 2 deletions
@@ -122,7 +122,8 @@ module Forwardable
end
# Takes a hash as its argument. The key is a symbol or an array of
- # symbols. These symbols correspond to method names. The value is
# the accessor to which the methods will be delegated.
#
# :call-seq:
@@ -160,9 +161,12 @@ module Forwardable
# Define +method+ as delegator instance method with an optional
# alias name +ali+. Method calls to +ali+ will be delegated to
- # +accessor.method+.
#
# class MyQueue
# extend Forwardable
# attr_reader :queue
# def initialize
@@ -170,12 +174,14 @@ module Forwardable
# end
#
# def_delegator :@queue, :push, :mypush
# end
#
# q = MyQueue.new
# q.mypush 42
# q.queue #=> [42]
# q.push 23 #=> NoMethodError
#
def def_instance_delegator(accessor, method, ali = method)
gen = Forwardable._delegator_method(self, accessor, method, ali)
@@ -3,6 +3,7 @@ require 'test/unit'
require 'forwardable'
class TestForwardable < Test::Unit::TestCase
RECEIVER = BasicObject.new
RETURNED1 = BasicObject.new
RETURNED2 = BasicObject.new
@@ -27,6 +28,16 @@ class TestForwardable < Test::Unit::TestCase
end
end
def test_def_instance_delegator_using_args_method_as_receiver
%i[def_delegator def_instance_delegator].each do |m|
cls = forwardable_class(