Skip to content

Instantly share code, notes, and snippets.

@toby55kij
Created October 10, 2010 09:48
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 toby55kij/619113 to your computer and use it in GitHub Desktop.
Save toby55kij/619113 to your computer and use it in GitHub Desktop.
// g100pon #70 存在しないメソッド/プロパティアクセスをフック
class Some {
def doMethod() {
println "Method!"
}
String name
def methodMissing(String name, args) {
println "method $name ( $args ) is missing!"
}
def propertyMissing(String name) {
println "property $name is missing!"
}
def propertyMissing(String name, value) {
println "property $name = $value is missing!"
}
}
def foo = new Some()
foo.doMethod()
foo.doOtherMethod(1, 2, 'three') //存在しないメソッド
foo.name = 'foo'
println foo.name
foo.age = 20 //存在しないプロパティへの書き込み
println foo.age //存在しないプロパティへのアクセス
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment