Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRubymethod_missing dispatch internalsSingle-choice MCQ

Why does redefining `respond_to_missing?` (not just `method_missing`) matter for the internals of `Object#method` and duck-typing, and what does this snippet print?

class Ghost def method_missing(name, *) name.to_s.upcase end def respond_to_missing?(name, include_private = false) name.to_s.start_with?("can_") end end g = Ghost.new p g.respond_to?(:can_fly) p g.respond_to?(:walk) p(g.method(:can_swim).call)