I use Blockenspiel to create DSL with Ruby. It works great and solves a lot of my problems, but I ran into the following problem, which is not strictly related to the Blockenspiel.
Suppose I have a DSL that looks like this:
dish do
name = 'Pizza'
ingredients = ...
nutrition_facts = ...
end
dish do
name = 'Doner'
ingredients = ...
nutrition_facts = ...
end
Now I have a menu compiler that takes dishes and compiles them into a menu. Now the compiler should compile several menu files, so it set and cleared the global context. This preferably occurs in parallel.
I found out that Sinatra uses class variables, but this has the consequence that it can do sequential processing and that you have to clear class variables when you want to compile a new menu. An alternative would be to use global variables.
I would prefer to evaluate DSL methods within an object so that there is no global context, and I could compile the menu in parallel, but the last time I tried it, I ran into some problems when declaring (helper-) methods in a menu file.
What methods are possible? What is the recommended way to do this?
user141335
source
share