Skip to content

Instantly share code, notes, and snippets.

@btolfa
Created April 1, 2012 07:51
Show Gist options
  • Save btolfa/2272957 to your computer and use it in GitHub Desktop.
Save btolfa/2272957 to your computer and use it in GitHub Desktop.
GroovyShell and Category
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