Actions
Bug #3352
closedDelegates: protected methods
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)
-
ensuretarget.respond_to?(m) ? target.public_send(m, *args, &block) : super
$@.delete_if {|t| %r"\A#{Regexp.quote(FILE)}:#{LINE-2}:"o =~ t} if $@
end
=end
Actions
Like0
Like0Like0