aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2018-03-04 21:45:02 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2018-03-04 21:48:10 +0100
commit092e4d7d9ffe621061e72471b95debe12d41f342 (patch)
tree910f3edbc922362ad7326f79272b84b11ac82c3d /activesupport
parentf4ddbff71c3f2171ad0bd7cb73e44ebf3a4ca245 (diff)
downloadrails-092e4d7d9ffe621061e72471b95debe12d41f342.tar.gz
rails-092e4d7d9ffe621061e72471b95debe12d41f342.tar.bz2
rails-092e4d7d9ffe621061e72471b95debe12d41f342.zip
[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.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb9
1 files changed, 4 insertions, 5 deletions
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 <tt>:private</tt> option.
+ # The delegated methods are public by default.
+ # Pass <tt>private: true</tt> 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:0x00000008221340>
- # User.new.religion # => NoMethodError: private method `religion' called for #<User:0x00000008221340>
+ # 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+,