Programming Quote by Armando Fox
““When Ruby programmers say that some class “quacks like an Array,” they usually mean that it’s not necessarily an Array nor a descendant of Array, but it responds to most of the same methods as Array and can therefore be used wherever an Array would be used.””
About This Quote
Source Talk: Programming Languages, Stanford CS 242, 2015
A class can be used like an Array if it implements the same methods, even without inheriting from Array.
In simple terms: Non‑Array class can act like an Array by matching its interface.
Design objects to match required interfaces.
Themes
Mood
Type
When to use this quote
- API design
- library usage
- code reuse
- testing
- refactoring
Key Concepts
Questions to Reflect On
- What methods must your class implement to be interchangeable?
- How does duck typing affect code safety?
If the class lacks subtle Array behaviors, substitution may fail.