From: Marc-Andre Lafortune Date: 2010-05-27T15:55:30+09:00 Subject: [ruby-core:30451] [Bug #3352] Delegates: protected methods Bug #3352: Delegates: protected methods http://redmine.ruby-lang.org/issues/show/3352 Author: Marc-Andre Lafortune Status: Open, Priority: Low Assigned to: Marc-Andre Lafortune, Category: lib, Target version: 1.9.2 ruby -v: trunk require 'delegate' class X protected def pro :foo end end obj = X.new obj.pro #=> NoMethodError: protected method `pro' called for # 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 ---------------------------------------- http://redmine.ruby-lang.org