So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. Let's say you want to STON-ify the following object: { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. Note there is a single quote character inside the #note. You can do that using #print: when needed. Here is an expression to see how that works: Compiler evaluate: (String streamContents: [ :out | out nextPutAll: 'STON fromString: '; print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). The Smalltalk expression then looks like this: STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. Is this what you need ?
On 12 Mar 2018, at 22:43, Stephane Ducasse <stepharo.self@gmail.com> wrote:
Hi
I want to write a method that generate a method that when I execute this recreates the objects that I STONified. (I love STON).
So I did something like that
descriptionMethodFrom: descriptionItems "self new descriptionMethodFrom: ChrysalConfigurationDescription itemDescriptionForXX"
^ String streamContents: [ :s | s nextPutAll: 'descriptions'; cr. s nextPutAll: '^ STON fromString: '. s nextPutAll: (STON toStringPretty: descriptionItems) ]
and I get of course something wrong :) because the strings are not doubel quoted and the first expression is not surrounded by single quote.
And I could do it but I want a smart way to do it. I was thinking that may be I'm missing something obvious.
descriptions ^ STON fromString: [ StringConfigurationItem { #propertyName : 'title', #default : 'my super cool book' }, BooleanConfigurationItem { #propertyName : 'verbose', #default : 'true' }, StringConfigurationItem { #propertyName : 'attribution', #default : 'me, myself and I' }, StringConfigurationItem { #propertyName : 'series', #default : 'Square Bracket Associate Collection' } ]