Currently, sord converts all duck types to untyped RBS types.
This makes perfect sense, as we don't know the signature of arbitrary duck types - what parameters they accept, what their types are, and what the return type is.
However, there are a couple of builtin interface type signatures in RBS, which can be considered universally valid.
Would it be possible to put references to these interfaces instead of unknown types into the generated RBS signatures?
For example:
# @param input [#to_s] the input to print
# @return [void]
def print(input)
puts input
end
would convert the input duck type #to_s to a reference to the _ToS builtin interface
def print: (_ToS input) -> void
Of course, currently, you can get a similar behavior by defining a ToS module yourself, and use that instead of #to_s
# @abstract
module ToS
def self.included(...)
raise "This marker interface is not meant to be included!"
end
def self.extended(...)
raise "This marker interface is not meant to be extended!"
end
# @abstract
# @return [String]
def to_s()
raise TypeError, "No implicit conversion to String possible."
end
end
However, this introduces unnecessary clutter to your codebase.
Currently, sord converts all duck types to
untyped
RBS types. This makes perfect sense, as we don't know the signature of arbitrary duck types - what parameters they accept, what their types are, and what the return type is.However, there are a couple of builtin interface type signatures in RBS, which can be considered universally valid. Would it be possible to put references to these interfaces instead of unknown types into the generated RBS signatures?
For example:
would convert the input duck type
#to_s
to a reference to the_ToS
builtin interfaceOf course, currently, you can get a similar behavior by defining a
ToS
module yourself, and use that instead of#to_s
However, this introduces unnecessary clutter to your codebase.