Friday 14 November 2008

Fun With Groovy Categories

Just a quick stupid trick I discovered. Commons Lang's StringUtils class works quite nicely as a category for String, e.g.
    use(StringUtils) {
println 'i can has cheezburger'.substringAfter('i can has ') // prints 'cheezburger'
}
Not only that but the JetGroovy plugin for IntelliJ IDEA will autocomplete all the new String methods inside the use block.

No comments: