The groovy idiomatic way is to keep a reference to the old method and call it inside the new one.
def oldPlus = Integer.metaClass.getMetaMethod("plus", [Integer] as Class[]) Integer.metaClass.plus = { Integer n -> return oldPlus.invoke(oldPlus.invoke(delegate, n), 1) } assert 5 == 2 + 2
This is actually not well documented, and I planned to post a blog post about this exact topic today or tomorrow :).
source share