Skip to content

Commit 616f302

Browse files
ghiculescup8
andcommitted
Be more explicit about lack of inheritance on thread_mattr_accessor
Co-authored-by: Petrik de Heus <[email protected]>
1 parent 826f947 commit 616f302

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

activesupport/lib/active_support/core_ext/module/attribute_accessors.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# == Attribute Accessors
4+
#
35
# Extends the module object with class/module and instance accessors for
46
# class/module attributes, just like the native attr* accessors for instance
57
# attributes.

activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
# == Attribute Accessors per Thread
4+
#
35
# Extends the module object with class/module and instance accessors for
46
# class/module attributes, just like the native attr* accessors for instance
57
# attributes, but does so on a per-thread basis.
@@ -111,16 +113,18 @@ def #{sym}=(obj)
111113
# Account.user # => "DHH"
112114
# Account.new.user # => "DHH"
113115
#
116+
# Unlike `mattr_accessor`, values are *not* shared with subclasses or parent classes.
114117
# If a subclass changes the value, the parent class' value is not changed.
115-
# Similarly, if the parent class changes the value, the value of subclasses
116-
# is not changed.
118+
# If the parent class changes the value, the value of subclasses is not changed.
117119
#
118120
# class Customer < Account
119121
# end
120122
#
121-
# Customer.user = "Rafael"
122-
# Customer.user # => "Rafael"
123-
# Account.user # => "DHH"
123+
# Account.user # => "DHH"
124+
# Customer.user # => nil
125+
# Customer.user = "Rafael"
126+
# Customer.user # => "Rafael"
127+
# Account.user # => "DHH"
124128
#
125129
# To omit the instance writer method, pass <tt>instance_writer: false</tt>.
126130
# To omit the instance reader method, pass <tt>instance_reader: false</tt>.

0 commit comments

Comments
 (0)