I'm doing some gross stuff, like using Groovy's metaClass and Eval to dynamically assign properties to an object from an XML import:
class ObjectBuilder {
def assignProp(String propName, String propValue) {
Eval.x(this, "x.metaClass.${propName} = '${propValue}'")
}
}
def h = new ObjectBuilder()
h.assignProp('name', 'Henson')
println(h.name)
What I'd like to do though, is be able instantiate another copy of the class inside itself:
Eval.x(this, "x.metaClass.${ObjName} = new ObjectBuilder()")
But I can't, because I think the class isn't passed to the binding. Is there another solution?