Reputation: 69920
Groovy allows to do some nice things with strings in frontend pages, like:
${"hello".capitalize()}
How can I add a new custom method to the String
class? Like:
${"hello".custom()}
Upvotes: 6
Views: 1058
Reputation: 264
Use the metaClass
String.metaClass.custom = { //dosomething }
See http://www.groovyexamples.org/2010/07/19/dynamically-add-properties-to-a-class/
Upvotes: 7