[Glass] Creating (or converting) SimpleBlocks

Johan Brichau via Glass glass at lists.gemtalksystems.com
Sat Jun 11 00:53:17 PDT 2016


Hi there,

We are creating and storing a decent amount of blockclosures in persistent objects. We want these to be simple blocks as they do not need any values from their lexical scope and we wish to ensure they do not reference any objects that might otherwise be gc’ed.

The way we do this right now is by passing these blocks through the following method:

convertToSimpleBlock: aBlock
	^ aBlock _sourceString evaluate

I’m not totally fond of this way: it uses a private Gs method.
However, creating blocks from strings directly in our application code makes it harder to use code refactoring tools as the code inside the string is not taken into consideration.
Another way to ensure that block’s lexical scope does not reference any undesirable objects is by following a code convention that explicitly creates a method in the object that will store it, and mind that there are no method arguments. However, some of these blocks are to be created in a class method, which would mean they reference that version of the class forever (undesirable in the light of future class migrations).

Is there any other way to create simple blocks? :)

Thanks for any suggestions
Johan


More information about the Glass mailing list