Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRubymethod_missing and respond_to_missingSingle-choice MCQ

When you build a transparent proxy by subclassing BasicObject and forwarding through `method_missing`, why is `def method_missing(name, *args, **kw, &blk); @t.public_send(name, *args, **kw, &blk); end` the correct signature in Ruby 3.x rather than `(name, *args, &blk)`?

class Proxy < BasicObject def initialize(t); @t = t; end def method_missing(name, *args, **kw, &blk) @t.public_send(name, *args, **kw, &blk) end def respond_to_missing?(n, ip = false) @t.respond_to?(n, ip) end end Proxy.new({a: 1}).fetch(:z, "default")