Message-ID: <1948469554.1551.1417211346098.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1550_1858321125.1417211346097" ------=_Part_1550_1858321125.1417211346097 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!