RosettaCodeData/Task/Respond-to-an-unknown-method-call/Sidef/respond-to-an-unknown-method-call.sidef
2016-12-05 23:44:36 +01:00

22 lines
650 B
Text

class Example {
method foo {
say "this is foo"
}
method bar {
say "this is bar"
}
method AUTOLOAD(_, name, *args) {
say ("tried to handle unknown method %s" % name);
if (args.len > 0) {
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”