Le duck typing, ou réponds-tu au message ?Duck typing, or do you answer the message?
Une méthode qui appelle x.quack fonctionne sur n'importe quel objet répondant à quack — sans interface à implémenter, sans superclasse commune. Le seul contrat, c'est le message. On ne demande pas quel type tu es : on demande si tu réponds.A method calling x.quack works on any object that responds to quack — no interface to implement, no shared superclass. The only contract is the message. We don't ask what type you are: we ask whether you respond.
AudienceAudience
Dev venant d'un langage à types, prêt à coder contre un protocoleDev from a typed language, ready to code against a protocol
Format
Self-paced
ChapitresChapters
5
Date
Fév 2026Feb 2026
≈ 18 min●●○○Duck typingProtocolerespond_to?
🔒
La suite est réservéeThe rest is members-only
Le premier numéro est libre. Débloque tout The Ruby Loop —
tous les volumes, à vie — pour 5 €, paiement unique.
The first issue is free. Unlock all of The Ruby Loop —
every volume, forever — for €5, one-time.