In theory: this should be possible:
# typed: true
require "type_toolkit"
module MyInterface
interface!
#: -> void
def demo; end
end
class Parent
def method_missing(m, ...)
return super unless m == :demo
puts "#demo implemented via #method_missing"
end
end
class Child < Parent
# Commenting out this module inclusion makes call succeed
include MyInterface
end
Child.new.demo
For comparison, Sorbet's static typechecker doesn't allow this, because it doesn't have any way to prove what is or isn't implemented by method_missing. Sorbet runtime raises an error, which can be a change in runtime behaviour (compared to what you would expect without it):
# typed: true
require "sorbet-runtime"
module MyInterface
extend T::Sig
extend T::Helpers
interface!
sig { abstract.void }
def demo; end
end
class Parent
def method_missing(m, ...)
return super unless m == :demo
puts "#demo implemented via #method_missing"
end
end
class Child < Parent
# Commenting out this module inclusion makes call succeed
include MyInterface
end
Child.new.demo # (NotImplementedError)
# The method `demo` on MyInterface is declared as `abstract`. It does not have an implementation.
In theory: this should be possible:
For comparison, Sorbet's static typechecker doesn't allow this, because it doesn't have any way to prove what is or isn't implemented by
method_missing. Sorbet runtime raises an error, which can be a change in runtime behaviour (compared to what you would expect without it):