Skip to content

Instantly share code, notes, and snippets.

@irof
Created March 26, 2011 15:44
Show Gist options
  • Save irof/888387 to your computer and use it in GitHub Desktop.
Save irof/888387 to your computer and use it in GitHub Desktop.
処理の差し替え
class Hello {void hello(){println "1"}}
def a = new Hello()
def b = new Hello()
b.metaClass.hello = { println "2" }
a.hello()
b.hello()
a.metaClass.hello = {b.metaClass.hello}
a.hello()
b.hello()
a.metaClass.hello = { println "3" }
a.hello()
b.hello()
a.&hello()
1
2
2
3
2
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment