solargraph
solargraph copied to clipboard
Factory types
Hello!
Is there a way to document that a function yields an instance of the class passed in as a parameter?
module Factoryish
def self.with_instance(some_class)
the_instance = some_class.new
yield the_instance
# some more code
end
end
Thank you for your help.
PS: Amazing, amazing work on this gem and the VS Code extension 👏 👏 👏 !
Thanks!
That's not possible yet, but I might be able to make it work based on the way that return types are inferred from methods with @!macro directives. Example:
module Factoryish
# @!macro
# @return [$1]
def self.make_instance(some_class); end
end
string = Factoryish.make_instance(String)
string # <= Type is String
For a yieldparam, it should look something like this:
module Factoryish
# @!macro
# @yieldparam [$1]
def self.with_instance(some_class)
the_instance = some_class.new
yield the_instance
# some more code
end
end
Factoryish.with_instance(String) do |instance|
instance # <= Type is String
end
I'll add it to the roadmap.
When you intend to implement this feature???