Reputation: 1473
Given a regular Groovy script, is there a way to access its binding variables from classes defined inside the script itself?
The following snippet
class Example {
def printBindings() {
for (var in binding.variables) {
println "$var.key - $var.value"
}
}
}
new Example().printBindings()
fails with the exception below:
groovy.lang.MissingPropertyException: No such property: binding for class: Example
Upvotes: 3
Views: 3421
Reputation: 171054
Not that I can find without passing the script through to the method:
class Example {
def printBindings( container ) {
for (var in container.binding.variables) {
println "$var.key - $var.value"
}
}
}
new Example().printBindings( this )
Upvotes: 1