Created
April 1, 2012 07:51
-
-
Save btolfa/2272957 to your computer and use it in GitHub Desktop.
GroovyShell and Category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shell = new GroovyShell() | |
shell.metaClass.invokeMethod = {String name, args -> | |
def metaMethod = delegate.metaClass.getMetaMethod(name, args) | |
def result | |
switch (name) { | |
case 'parse': | |
result = metaMethod.invoke(delegate, args) | |
def oldRun = result.metaClass.getMetaMethod('run') | |
result.metaClass.run = { -> | |
def result2 | |
def delcopy = delegate | |
use(FormulaCategory) { | |
result2 = oldRun.invoke(delcopy) | |
} | |
result2 | |
} | |
break | |
case 'evaluate': | |
def delcopy = delegate | |
use(FormulaCategory) { | |
result = metaMethod.invoke(delcopy, args) | |
} | |
break | |
default: | |
result = metaMethod.invoke(delegate, args) | |
} | |
result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment