Project

General

Profile

Actions

Bug #3352

closed

Delegates: protected methods

Added by marcandre (Marc-Andre Lafortune) over 14 years ago. Updated over 13 years ago.

Status:
Rejected
Target version:
ruby -v:
trunk
Backport:
[ruby-core:30451]

Description

=begin
require 'delegate'

 class X
   protected
     def pro
       :foo
     end
 end
 obj = X.new

 obj.pro #=> NoMethodError: protected method `pro' called for #<X:0x000001008a2a68>
 SimpleDelegator.new(obj).pro #=> :foo

I feel it would be more sensible to raise a NoMethodError.

No test seem to be testing for protected access, nor does RubySpec.

Unless there is objection, I'll commit the following:

diff --git a/lib/delegate.rb b/lib/delegate.rb
index f366091..93fbc37 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -141,7 +141,7 @@ class Delegator < BasicObject
def method_missing(m, *args, &block)
target = self.getobj
begin

  •  target.respond_to?(m) ? target.__send__(m, *args, &block) : super(m, *args, &block)
    
  •  target.respond_to?(m) ? target.public_send(m, *args, &block) : super
    
    ensure
    $@.delete_if {|t| %r"\A#{Regexp.quote(FILE)}:#{LINE-2}:"o =~ t} if $@
    end
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0