Respond to an unknown method call: Difference between revisions

Content added Content deleted
(Add SuperCollider example)
Line 1,092: Line 1,092:
True
True
slate[2]></lang>
slate[2]></lang>

=={{header|SuperCollider}}==
<lang SuperCollider>
Ingorabilis {

tell {
"I told you so".postln;
}

find {
"I found nothing".postln
}

doesNotUnderstand { |selector ... args|
"Method selector '%' not understood by %\n".postf(selector, this.class);
"Giving you some good arguments in the following".postln;
args.do { |x| x.postln };
"And now I delegate the method to my respected superclass".postln;
super.doesNotUnderstand(selector, args)
}

}
</lang>

Usage:



=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Line 1,144: Line 1,170:
There is a utility method for exactly the above (it catches only #fooBar to the original receiver):
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>
<lang smalltalk>anObject perform:#fooBar ifNotUnderstood:[ ...some alternative code and return value... ].</lang>

<lang SuperCollider>
i = Ingorabilis.new;
i.tell; // prints "I told you so"
i.find; // prints ""I found nothing"
i.think(1, 3, 4, 7);
</lang>

The latter answers:
<lang SuperCollider>Method selector 'think' not understood by Ingorabilis
Giving you some good arguments in the following
1
3
4
7
And now I delegate the method to my respected superclass
ERROR: Message 'think' not understood.
RECEIVER:
Instance of Ingorabilis { (0x1817b1398, gc=D4, fmt=00, flg=00, set=00)
instance variables [0]
}
<...></lang>


=={{header|Tcl}}==
=={{header|Tcl}}==