[squeak-dev] [ANN] STON - Smalltalk Object Notation
Sven Van Caekenberghe
sven at beta9.be
Tue May 8 06:59:18 UTC 2012
On 07 May 2012, at 22:07, Sven Van Caekenberghe wrote:
> But you could overwrite #stonOn: and #fromSton: specifically for Fractions, maybe like this:
>
> Float>>#stonOn: stonWriter
> stonWriter writeObject: self streamShortList: [ :array |
> array add: numerator; add: denominator ]
>
> Float class>>#fromSton: stonReader
> | representation |
> representation := stonReader parseList.
> ^ self
> numerator: representation first
> denominator: representation second
>
> This would then result in
>
> String streamContents: [ :stream |(STONWriter on: stream) nextPut: 3/4]
>
> ==> 'Fraction[3,4]'
(TYPO)
But you could overwrite #stonOn: and #fromSton: specifically for Fractions, maybe like this:
Fraction>>#stonOn: stonWriter
stonWriter writeObject: self streamShortList: [ :array |
array add: numerator; add: denominator ]
Fraction class>>#fromSton: stonReader
| representation |
representation := stonReader parseList.
^ self
numerator: representation first
denominator: representation second
This would then result in
String streamContents: [ :stream |(STONWriter on: stream) nextPut: 3/4]
==> 'Fraction[3,4]'
Sorry,
Sven
More information about the Squeak-dev
mailing list
|