Skip to content

Commit 100ad43

Browse files
authored
Merge pull request rails#43324 from ghiculescu/patch-5
Be more explicit about lack of inheritance on `thread_mattr_accessor`
2 parents 060ae8c + 616f302 commit 100ad43

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.
@@ -116,16 +118,18 @@ def #{sym}=(obj)
116118
# Account.user # => "DHH"
117119
# Account.new.user # => "DHH"
118120
#
121+
# Unlike `mattr_accessor`, values are *not* shared with subclasses or parent classes.
119122
# If a subclass changes the value, the parent class' value is not changed.
120-
# Similarly, if the parent class changes the value, the value of subclasses
121-
# is not changed.
123+
# If the parent class changes the value, the value of subclasses is not changed.
122124
#
123125
# class Customer < Account
124126
# end
125127
#
126-
# Customer.user = "Rafael"
127-
# Customer.user # => "Rafael"
128-
# Account.user # => "DHH"
128+
# Account.user # => "DHH"
129+
# Customer.user # => nil
130+
# Customer.user = "Rafael"
131+
# Customer.user # => "Rafael"
132+
# Account.user # => "DHH"
129133
#
130134
# To omit the instance writer method, pass <tt>instance_writer: false</tt>.
131135
# To omit the instance reader method, pass <tt>instance_reader: false</tt>.

0 commit comments

Comments
 (0)