class Handler { def messages = [] def methodMissing(String name, args) { messages << [name,args] } def playBack(obj) { messages.each { name, args -> obj."$name"(args) } } } class Something { def methodMissing(String name, args) { println "$name $args" } def doThis(obj) { println "doThis" } def doThat(obj) { println "doThat" } } def handler1 = new Handler() handler1.doThis "t" handler1.doThat "test" handler1.doNothing "testing" handler1.playBack new Something() handler1.doNothing "testing" handler1.doThat "test" handler1.doThis "t" handler1.playBack new Something() def handler2 = new Handler() handler2.doNothing "testing" handler2.doThat "test" handler2.doThis "t" def something = new Something() something.metaClass."doThis" = { println "new doThis" } handler2.playBack something