I need another method on String. I used metaClass to do this:
However, in all of the code examples I've seen on metaClass this trick has always been inside a script. In my application, though, I'm not running scripts - I have Groovy classes. I suppose I could place this metaClass thing in the beginning of any method that needs to call it... but that sure doesn't feel right.
I thought about moving it to some listener or bootstrapper class that loads when my container loads, but then I have to make sure it also gets called for my unit tests and that feels sloppy too.
Should metaClass not be used like this in an application (and keep it only in scripts)? Should I revert to the old school Java way and make a String utility class? [ April 08, 2008: Message edited by: Marc Peabody ]
Can you have this code in a static initialization block of a prominent class in your application? If this prominent class is guaranteed to be loaded pretty early in your application execution, you don't have to worry about making explicit calls to this code...