|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
| 3 | +# == Attribute Accessors per Thread |
| 4 | +# |
3 | 5 | # Extends the module object with class/module and instance accessors for
|
4 | 6 | # class/module attributes, just like the native attr* accessors for instance
|
5 | 7 | # attributes, but does so on a per-thread basis.
|
@@ -116,16 +118,18 @@ def #{sym}=(obj)
|
116 | 118 | # Account.user # => "DHH"
|
117 | 119 | # Account.new.user # => "DHH"
|
118 | 120 | #
|
| 121 | + # Unlike `mattr_accessor`, values are *not* shared with subclasses or parent classes. |
119 | 122 | # 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. |
122 | 124 | #
|
123 | 125 | # class Customer < Account
|
124 | 126 | # end
|
125 | 127 | #
|
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" |
129 | 133 | #
|
130 | 134 | # To omit the instance writer method, pass <tt>instance_writer: false</tt>.
|
131 | 135 | # To omit the instance reader method, pass <tt>instance_reader: false</tt>.
|
|
0 commit comments