Commit 72d8359
committed
fix(class_methods): define instance reader at declaration time
Moves the instance reader definition for attributes declared with
simple_class_attribute out of the singleton setter and into the
attribute declaration itself.
Earlier behavior: the instance method (e.g., flag) was defined only when
the class setter (klass.flag = ...) ran. That caused instances to lack
the reader method until the setter had been called.
New behavior: when simple_class_attribute :name is declared, the
instance reader name is defined immediately (but it still checks an
instance ivar first and falls back to the singleton-class value if the
ivar isn't set). The class setter now only defines the singleton reader
to return the assigned value.
Why?:
Fixes a NoMethodError in the failing spec where an instance reader is
expected to exist even if the class-level setter hasn't been used yet
(for example, the test that sets instance.instance_variable_set('@Flag',
'local') and expects instance.flag to return 'local').
Behavior is preserved: instance-level overrides still take precedence
(instance ivar wins), and setting the instance ivar does not change the
singleton class value.1 parent 13d9709 commit 72d8359
2 files changed
Lines changed: 16 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
31 | 46 | | |
32 | 47 | | |
33 | 48 | | |
34 | 49 | | |
35 | 50 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
0 commit comments