golo-lang/golo-lang — pull request #119 by danielpetisme (2013-12-15 23:27:06+00:00)
Title: Add a fallback mechanism for Dynamic Objects method invocation

A new ```fallback``` helper method completes the Dynamic Object API.
Defining a ```fallback``` let the user the possibility to explain what to do if the target property does not exist. Behind the scene, the target property invocation is now guarded with test. This test simply check the existence of the property. If the property does not exist, then the fallback method will be triggered.

Example:
```
module foo

function main = |args| {
let dynob = DynamicObject():
fallback(|this, property, args...| -> "Dispatch failed for property: " + property + ", with args:" + args: asList(): join(" "))

println(dynob: casperGetter())
#Setter-like invocation creates the property, thus the fallback can't be invoked.
println(dynob: casperSetter("foo"))
println(dynob: casperMethod("foo", "bar"))
}
```
Output
```
Dispatch failed for property: casperGetter, with args:
gololang.DynamicObject@56d5525
Dispatch failed for property: casperMethod, with args:foo bar
```

The fallback parameters must be:
* ```this```: the receiver object as usual
* ```property```: the property we try to invoke
* ```args```: a trailing varargs parameter which capture the parameters of the initial property invocation.