...
| Code Block |
|---|
class Person {
String name = "Fred"
}
Person.metaClass.getProperty = { String name ->
def metaProperty = Person.metaClass.getMetaProperty(name)
def result
if(metaProperty) result = metaProperty.getProperty(delegate)
else {
result = "FlintstroneFlintstone"
}
result
}
def p = new Person()
assert "Fred" == stfp.name
assert "Flintstone" == stfp.other
|
The important thing to note here is that instead of a MetaMethod we look-up a MetaProperty instance if that exists we call the getProperty method of the MetaProperty passing the delegate (ie the instance of the class).
...