|
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.
|
@@ -111,16 +113,18 @@ def #{sym}=(obj)
|
111 | 113 | # Account.user # => "DHH"
|
112 | 114 | # Account.new.user # => "DHH"
|
113 | 115 | #
|
| 116 | + # Unlike `mattr_accessor`, values are *not* shared with subclasses or parent classes. |
114 | 117 | # 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. |
117 | 119 | #
|
118 | 120 | # class Customer < Account
|
119 | 121 | # end
|
120 | 122 | #
|
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" |
124 | 128 | #
|
125 | 129 | # To omit the instance writer method, pass <tt>instance_writer: false</tt>.
|
126 | 130 | # To omit the instance reader method, pass <tt>instance_reader: false</tt>.
|
|
0 commit comments