Message-ID: <2042720997.17111.1414032275329.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_17110_520413883.1414032275328" ------=_Part_17110_520413883.1414032275328 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Since Groovy allows you to use Strings as property names this in turns a= llows you to dynamically create method and property names at runtime.= =20
To create a method with a dynamic name simply use Groovy's feature of re= ference property names as strings. You can combine this with Groovy's strin= g interpolation (Gstrings) to create method and property names on the fly:<= /p>=20=20
The same concept can be applied to static methods and properties.=20
In Grails we have a concept of dynamic codecs, classes that can encode a= nd decode data.=20
So what we do with these classes is to evaluate the convention and add &= quot;encodeAsXXX" methods to every object based on the first part of t= he name of the codec class such as "encodeAsHTML". The pseudo cod= e to achieve this is below:=20 =20
As you can see from the above we dynamically construct the names of the = methods using GString expressions!