views:

41

answers:

1

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?

+1  A: 

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)
danb