Respond to an unknown method call: Difference between revisions

Content added Content deleted
m (Added Sidef language)
(Added groovy version)
Line 344: Line 344:
</pre>
</pre>


=={{header|Groovy}}==
Groovy allows us to capture all unknown method calls using the methodMissing function
<lang groovy>class MyObject {
def foo() {
println 'Invoked foo'
}
def methodMissing(String name, args) {
println "Invoked missing method $name$args"
}
}</lang>

Testing:
<lang groovy>def o = new MyObject()
o.foo()
o.bar()
o.bar(1, 2, 'Test')</lang>

{{out}}
<pre>
Invoked foo
Invoked missing method bar[]
Invoked missing method bar[1, 2, Test]
</pre>
==Icon and {{header|Unicon}}==
==Icon and {{header|Unicon}}==
Unicon implements objects via a translator that emits native code. While Icon does not support objects, the native code could potentially be translated and run under Icon provided other Unicon extensions are not used.
Unicon implements objects via a translator that emits native code. While Icon does not support objects, the native code could potentially be translated and run under Icon provided other Unicon extensions are not used.