Respond to an unknown method call: Difference between revisions

Content added Content deleted
(Tagged as "omit from" for MATLAB)
m (Added Sidef language)
Line 894: Line 894:
tried to handle unknown method ding
tried to handle unknown method ding
it had arguments: dong</pre>
it had arguments: dong</pre>

=={{header|Sidef}}==
The special '''AUTOLOAD''' method gets called when a method isn't defined in the current class:
<lang ruby>class Example {
method foo {
say "this is foo"
};
method bar {
say "this is bar"
};
method AUTOLOAD(name) {
say ("tried to handle unknown method %s" % name);
if (var args = _; args.len?) {
say ("it had arguments: %s" % args.join(', '));
}
}
}

var example = Example.new;

example.foo; # prints “this is foo”
example.bar; # prints “this is bar”
example.grill; # prints “tried to handle unknown method grill”
example.ding("dong"); # prints “tried to handle unknown method ding”
# prints “it had arguments: dong”</lang>


=={{header|Slate}}==
=={{header|Slate}}==