Geo
Geo

Reputation: 96767

Is there a way of passing all the defined variables to a GroovyShell?

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

Answers (1)

danb
danb

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

Related Questions