« Return to Thread: Adding method as GString expression to per-instance metaclass

Adding method as GString expression to per-instance metaclass

by Setya :: Rate this Message:

Reply to Author | View in Thread

Hi all,

I tried to add dynamic method to per-instance metaclass, the method itself is in the form of GString expression as follows:

def emc = new ExpandoMetaClass(Expando);
def methodName = 'getTest';
emc."$methodName" = {-> println 'Hello World';};
emc.initialize();

def expando = new Expando();
expando.metaClass = emc;

Than I call the method :

expando.test;

No error was thrown but the closure within 'getTest' is never called

Any ideas ?

Regards,

Setya

 « Return to Thread: Adding method as GString expression to per-instance metaclass