0
votes

I have a groovy script, Bootstrap.groovy, where I have defined several metaclass methods on the String class. I have my test cases in another file Test.groovy. How do I make the metaclass methods available in the Test.groovy, when manipulating String? (Iow, how do I make the metaclass methods globally available in other scripts/programs)?

(I did search and find some related questions, but they did not answer this specifically. Im using Groovy 1.8.4)

2

2 Answers

0
votes

Use the DelegatingMetaClass to make these additions to the String class globally visible.

0
votes

I think I found a way to do this: just call evaluate(new File("ch8/Bootstrap.groovy")) in Test.groovy. Previously I was trying new GroovyShell().evaluate(), but thats not required. I could directly call the evaluate() method.