Respond to an unknown method call: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Omitted languages: add Processing) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 201:
Tried to handle unknown method 'grill'
Tried to handle unknown method 'ding', with arguments: dong 11 </pre>
=={{header|Déjà Vu}}==
The function <code>set-default</code> is useful here:
Line 242 ⟶ 243:
}
}</lang>
=={{header|Elena}}==
Using generic handler (ELENA 4.x):
Line 950 ⟶ 952:
return 0;
}</lang>
=={{header|Oforth}}==
Line 1,056 ⟶ 1,057:
$example->ding("dong"); # prints "tried to handle unknown method Example::ding"
# and "it had arguments: dong"</lang>
=={{header|Perl 6}}==▼
<lang perl6>class Farragut {▼
method FALLBACK ($name, *@rest) {▼
say "{self.WHAT.perl}: $name.tc() the @rest[], full speed ahead!";▼
}▼
}▼
class Sparrow is Farragut { }▼
Farragut.damn: 'torpedoes';▼
Sparrow.hoist: <Jolly Roger mateys>;</lang>▼
{{out}}▼
<pre>Farragut: Damn the torpedoes, full speed ahead!▼
Sparrow: Hoist the Jolly Roger mateys, full speed ahead!</pre>▼
<tt>[http://design.perl6.org/S12.html#FALLBACK_methods FALLBACK]</tt> will be called for any method that is not defined. Since any class inherits from <tt>Any</tt>, there will be plenty of already defined methods. Those which are not defined can also be used as L-Values by the magic of <tt>[http://design.perl6.org/S12.html#Lvalue_methods is rw]</tt>. ▼
<lang perl6>class L-Value { ▼
our $.value = 10;▼
method FALLBACK($name, |c) is rw { $.value }▼
}▼
my $l = L-Value.new;▼
say $l.any-odd-name; # 10▼
$l.some-other-name = 42;▼
say $l.i-dont-know; # 42</lang>▼
=={{header|Phix}}==
Line 1,252 ⟶ 1,226:
;; => No method in #<generic:foo> for "one"
</lang>
(formerly Perl 6)
▲<lang perl6>class Farragut {
▲ method FALLBACK ($name, *@rest) {
▲ say "{self.WHAT.perl}: $name.tc() the @rest[], full speed ahead!";
▲ }
▲}
▲class Sparrow is Farragut { }
▲Farragut.damn: 'torpedoes';
▲Sparrow.hoist: <Jolly Roger mateys>;</lang>
▲{{out}}
▲<pre>Farragut: Damn the torpedoes, full speed ahead!
▲Sparrow: Hoist the Jolly Roger mateys, full speed ahead!</pre>
▲<tt>[http://design.perl6.org/S12.html#FALLBACK_methods FALLBACK]</tt> will be called for any method that is not defined. Since any class inherits from <tt>Any</tt>, there will be plenty of already defined methods. Those which are not defined can also be used as L-Values by the magic of <tt>[http://design.perl6.org/S12.html#Lvalue_methods is rw]</tt>.
▲<lang perl6>class L-Value {
▲ our $.value = 10;
▲ method FALLBACK($name, |c) is rw { $.value }
▲}
▲my $l = L-Value.new;
▲say $l.any-odd-name; # 10
▲$l.some-other-name = 42;
▲say $l.i-dont-know; # 42</lang>
=={{header|Ruby}}==
Line 1,369 ⟶ 1,372:
True
slate[2]></lang>
=={{header|Smalltalk}}==
Line 1,422 ⟶ 1,424:
There is a utility method for exactly the above (it catches only #fooBar to the original receiver):
<lang smalltalk>anObject perform:#fooBar ifNotUnderstood:[ ...some alternative code and return value... ].</lang>
=={{header|SuperCollider}}==
|