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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.