Wednesday, August 25, 2010

dynamic fields with groovy

one of the features I love is to just define new fields in objects whenever I want.

like:



def test = ["a","b","c,"]

Object a = new Object()

test.each{

a.metaClass."${it}" = it
}



generates te following fields in the object a

a.a = "a"
a.b = "b"
a.c = "c"

works incredible well with the grails export plugin :)

No comments:

Post a Comment