A deep dive into Ruby's two main polymorphism mechanisms: duck typing and classical inheritance. Using a payment processing system as a running example, the post explains how to identify hidden duck types by spotting case-on-class antipatterns, how to build implicit interfaces enforced through RSpec shared examples, and when to prefer inheritance instead. For inheritance, it covers the promote-not-demote refactoring strategy, the Template Method pattern, and Hook Messages as a way to eliminate hidden super coupling. Concludes by connecting both techniques to the Liskov Substitution and Open/Closed principles.
64 Impressions