[Cuis-dev] clever or silly idea?
Mark Volkmann
r.mark.volkmann at gmail.com
Tue Jun 11 16:29:24 PDT 2024
A thought occurred to me that I could override the instance method
`doesNotUnderstand` in a class to avoid writing a bunch of basic accessor
methods. Setting aside whether it's ever a good idea to have a getter and
setter method for every instance variable in a class, I thought I could do
it like this:
doesNotUnderstand: aMessage
"gets or sets an instance variable"
| argCount getters key setters value |
argCount := aMessage numArgs.
argCount > 1 ifTrue: [ ^super doesNotUnderstand: aMessage ].
key := aMessage keywords first.
getters := self class allInstVarNames.
setters := getters collect: [ :name | name, ':' ].
(getters, setters includes: key) ifFalse: [ ^super doesNotUnderstand:
aMessage ].
argCount = 0 ifTrue: [ ^self perform: key ].
value := aMessage arguments first.
self perform: key with: value
But this goes into an infinite loop because sending the `perform:` message
ends up hitting `doesNotUnderstand` again. Is there a way I could make this
work?
--
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240611/71a442a8/attachment-0001.htm>
More information about the Cuis-dev
mailing list