Hi,
Do I need to worry about closing a WriteStream? Currently I am working like this:
buildStatementFor: anObject | statement | statement := String new writeStream. [ statement nextPutAll: 'bla bla bla'. ^ statement contents. ] ensure: statement close
... is that not needed?
Thanks, Tim
On 26.11.2008, at 02:10, Mr. Timothy C. Johnson wrote:
Hi,
Do I need to worry about closing a WriteStream? Currently I am working like this:
buildStatementFor: anObject | statement | statement := String new writeStream. [ statement nextPutAll: 'bla bla bla'. ^ statement contents. ] ensure: statement close
... is that not needed?
Not for an in-memory write stream no.
Note you're missing the block brackets around [statement close].
Also, since this is such a common task, the shorter version is
buildStatementFor: anObject
^String streamContents: [:statement | statement nextPutAll: 'bla bla bla']
Take a look at #streamContents: which does exactly the same as your code, but you can never get it wrong again ;)
- Bert -
beginners@lists.squeakfoundation.org