From 092e4d7d9ffe621061e72471b95debe12d41f342 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 4 Mar 2018 21:45:02 +0100 Subject: [ci skip] Fix grammar in delegate, private: true docs. Convert the user to atheism by ditching the extra example that demonstrates the same thing as date_of_birth. Demonstrate the NoMethodError on date_of_birth first, then call age that uses date_of_birth internally. Thus showing that accessing it publicly fails, but using it internally succeeds. --- activesupport/lib/active_support/core_ext/module/delegation.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/module') diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 45d16515d2..ec3497173f 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -114,23 +114,22 @@ class Module # invoice.customer_name # => 'John Doe' # invoice.customer_address # => 'Vimmersvej 13' # - # If you want the delegate methods to be a private, - # use the :private option. + # The delegated methods are public by default. + # Pass private: true to change that. # # class User < ActiveRecord::Base # has_one :profile # delegate :first_name, to: :profile - # delegate :date_of_birth, :religion, to: :profile, private: true + # delegate :date_of_birth, to: :profile, private: true # # def age # Date.today.year - date_of_birth.year # end # end # - # User.new.age # => 2 # User.new.first_name # => "Tomas" # User.new.date_of_birth # => NoMethodError: private method `date_of_birth' called for # - # User.new.religion # => NoMethodError: private method `religion' called for # + # User.new.age # => 2 # # If the target is +nil+ and does not respond to the delegated method a # +Module::DelegationError+ is raised. If you wish to instead return +nil+, -- cgit v1.2.3