What is duck typing and how does Ruby implement it?

Last updated 27 June 2026

Duck typing means an object's suitability is determined by what methods it responds to, not by its class: "if it walks like a duck and quacks like a duck, it's a duck." Ruby implements this through dynamic method dispatch rather than declared interfaces.

  • Behavior over type: Code only cares that an object responds to the methods it calls, so any object with a each or to_s can be passed in.

  • No interface declarations: Unlike Java/C#, Ruby has no implements; compatibility is checked at call time when the method is dispatched.

  • Tools that support it: respond_to? to check capability, and method_missing to respond dynamically.

  • Trade-off: Flexibility and easy polymorphism, but errors surface at runtime rather than compile time, so tests matter more.

[lang:ruby] def serialize(thing) thing.to_json # works for anything that responds to to_json end

  • https://www.turing.com/interview-questions/ruby
  • https://www.youtube.com/watch?v=lkunzd5uDrw
  • https://blog.jacobvosmaer.nl/0004-ruby-scheduler-interaction/
  • https://wohotech.in/coding/top-java-interview-questions
  • https://jetthoughts.com/blog/ruby-3-4-yjit-performance-guide/
  • https://speed.ruby-lang.org/
  • https://flexiple.com/python/interview-questions
  • https://www.it-jobs-nl.com/ruby-developer/
  • https://www.bacancytechnology.com/blog/outsource-ruby-on-rails-development
  • https://blog.nextideatech.com/how-to-hire-the-best-ruby-on-rails-developers-the-complete-guide/
  • https://ubiminds.com/en-us/ruby-on-rails-developers/
  • https://dataford.io/interview-guides/pattern/software-engineer
  • https://www.reddit.com/r/rails/comments/1shfrbq/3_years_rails_dev_but_failed_basic_interview/
  • https://medium.com/@hpultimatemedia/advanced-ruby-programming-tutorial-9bebc6335c21
  • https://hellointern.in/blog/ruby-interview-questions-and-answers-for-2-years-experience-28493
  • https://www.reddit.com/r/rails/comments/1eb4wfx/ruby_on_rails_role_interview_what_questions_to/
  • https://news.ycombinator.com/item?id=42495135
  • https://www.adaface.com/blog/ruby-on-rails-interview-questions/
  • https://lemon.io/interview-questions/python/
  • https://www.kore1.com/hire-elixir-developers-2026/
  • https://www.testgorilla.com/blog/elixir-developer-interview-questions/
  • https://pragtob.wordpress.com/
  • https://www.shivabhusal.com/2026/01/19/deduplication-of-string-objects-for-memory-efficiency-and-performance/
All Ruby interview questions