I have a groovy script with an unknown number of variables in context at runtime, how do I find them all and print the name and value of each?
相关问题
- Grails External Configuration. Can't access to
- Can I override cast operator in Groovy?
- Use Groovy to Sort XML File
- mv wrapped inside an if in shell scripting
- Why do I use double quotes in shell scripts [dupli
相关文章
- Is there a non-java, cross platform way to launch
- Using Spring Dynamic Languages Support from Groovy
- Grails: How to make everything I create Upper Case
- Groovy Java 9 modules support
- Capture output of a bash command, parse it and sto
- Groovy: What's wrong with this “Hello World” p
- Create WS security headers for REST web service in
- Groovy can't compile the code from a solution
Well, if you're using a simple script (where you don't use the "def" keyword), the variables you define will be stored in the binding and you can get at them like this:
Prints:
I'm not aware of an easy way to enumerate through the variables defined with the "def" keyword, but I'll be watching this question with interest to see if someone else knows how.
Actually, Ted's answer will also work for 'def'ed variables.
yields
I'm not sure what the _-variables signify, but I'm sure you can work around them.