diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 72988fa6b5a..4a899a7d84d 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/object/public_send' + class Module # Provides a delegate class method to easily expose contained objects' methods # as your own. Pass one or more methods (specified as symbols or strings) diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index a24f013d4f1..d4ce81fdfa2 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -27,6 +27,8 @@ module Yz end Somewhere = Struct.new(:street, :city) do + attr_accessor :name + protected def protected_method @@ -40,6 +42,7 @@ end class Someone < Struct.new(:name, :place) delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place + delegate :name=, :to => :place, :prefix => true delegate :upcase, :to => "place.city" FAILED_DELEGATE_LINE = __LINE__ + 1 @@ -85,6 +88,11 @@ class ModuleTest < Test::Unit::TestCase assert_equal "Chicago", @david.city end + def test_delegation_to_assignment_method + @david.place_name = "Fred" + assert_equal "Fred", @david.place.name + end + def test_delegation_to_protected_method assert_raise(NoMethodError) { @david.protected_method } end