Jump to content

Respond to an unknown method call: Difference between revisions

Added groovy version
m (Added Sidef language)
(Added groovy version)
Line 344:
</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}}==
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.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.