diff options
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 6 | ||||
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 14 |
2 files changed, 19 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index fe680c87b8..7f968d10b5 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -267,7 +267,11 @@ class Module end def method_missing(method, *args, &block) - #{target}.send(method, *args, &block) + if #{target}.respond_to?(method) + #{target}.public_send(method, *args, &block) + else + super + end end RUBY end diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 0120aae492..75490bf4c9 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -40,6 +40,12 @@ class Someone < Struct.new(:name, :place) FAILED_DELEGATE_LINE_2 = __LINE__ + 1 delegate :bar, :to => :place, :allow_nil => true + + private + + def private_name + "Private" + end end Invoice = Struct.new(:client) do @@ -338,6 +344,14 @@ class ModuleTest < ActiveSupport::TestCase assert_equal "David", DecoratedReserved.new(@david).name end + def test_delegate_to_missing_does_not_delegate_to_private_methods + e = assert_raises(NoMethodError) do + DecoratedReserved.new(@david).private_name + end + + assert_match(/undefined method `private_name' for/, e.message) + end + def test_parent assert_equal Yz::Zy, Yz::Zy::Cd.parent assert_equal Yz, Yz::Zy.parent |