Reputation: 96767
Right now, when I'm trying to eval a piece of code in Groovy, I have to do something like this :
new GroovyShell(new Binding([var1:var1])).evaluate(line)
This can be pretty nasty when you have a lot of variables defined. Is there a better way of doing this? Is there something like Python's locals
, or something similar that lists all the declared variables?
Upvotes: 3
Views: 282
Reputation: 10379
I haven't tested this... but it may work:
new GroovyShell(this.binding).evaluate(line)
or this:
new GroovyShell(new Binding(this.binding.variables)).evaluate(line)
Upvotes: 3