I have a given dictionary and want to map it to an object of a specific class.
All keys of the dictionary should be mapped to equally named instance variables of the object.
I guess this is a common procedure? What is the common way to accomplish it?
Consider doing something like this:
dict := { #x -> 5 . #y -> 6 } asDictionary. "dictionary as you described"
basicObj := Point basicNew. "basic instance of your object"
dict keysAndValuesDo: [ :key :val |
basicObj instVarNamed: key put: val ].
^ basicObj
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With