Deal with method_missing
Will there be a way to deal with overriding method_missing? For instance, if I delegate the method calls to an instance variable, I'd like to "inherit" this object's API:
def method_missing(meth, *args)
if @obj.respond_to?(meth)
@obj.__send__(meth, *args)
else
super
end
end
There is no good support for #method_missing. If you have a set of methods available in the class, you can write method type definitions for them even if it is implemented by #method_missing.
You can include an interface to declare a class has a set of methods.
interface _FooBar
def foo: () -> void
def bar: () -> void
end
class FooBarBaz
include _FooBar # Equivalent to writing defs for #foo and #bar.
def baz: () -> void
end
I can, but that doesn't look very DRY. Looking at my example, if @obj is an array for instance; Array definitions are done in a class, not an interface. So in order for it to work for me, I'd have to "repeat" the Array class definitions in interface.
An alternative could be for rbs to allow inclusion of classes, or even a DSL method to extract a class interface:
# something like:
classFooBarBaz
include Array.interface