Last active
June 12, 2024 03:54
-
-
Save codefrau/3dc9e1a3020bb92864c57c4323041aec to your computer and use it in GitHub Desktop.
DNU to get/set inst vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doesNotUnderstand: aMessage | |
"gets or sets an instance variable" | |
| argCount getters key setters value index | | |
argCount := aMessage numArgs. | |
argCount > 1 ifTrue: [ ^super doesNotUnderstand: aMessage ]. | |
key := aMessage keywords first. | |
getters := self class allInstVarNames. | |
index := getters indexOf: key. | |
index > 0 ifTrue: [^self instVarAt: index]. | |
setters := getters collect: [ :name | name, ':' ]. | |
index := setters indexOf: key. | |
index > 0 ifTrue: [ | |
value := aMessage arguments first. | |
^self instVarAt: index put: value]. | |
^super doesNotUnderstand: aMessage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment