Skip to content

Instantly share code, notes, and snippets.

@rrees
Created January 23, 2009 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrees/50815 to your computer and use it in GitHub Desktop.
Save rrees/50815 to your computer and use it in GitHub Desktop.
class MyClass {
Closure aMethod
MyClass() {
aMethod = {println "Default"}
}
}
def myObject = new MyClass(aMethod: { println "Hello"})
print "Original method: "; myObject.aMethod()
def oldMethod = myObject.aMethod
myObject.aMethod = { println "Goodbye" }
print "Overridden method: "; myObject.aMethod()
myObject.aMethod = oldMethod
print "Restored method: "; myObject.aMethod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment