[Newbies] closing WriteStream?
bert at freudenbergs.de
Wed Nov 26 09:42:49 UTC 2008
On 26.11.2008, at 02:10, Mr. Timothy C. Johnson wrote:
> Do I need to worry about closing a WriteStream? Currently I am
> 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
^String streamContents: [:statement | statement nextPutAll: 'bla bla
Take a look at #streamContents: which does exactly the same as your
code, but you can never get it wrong again ;)
- Bert -
More information about the Beginners