Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory types #191

Open
guzart opened this issue Jun 15, 2019 · 2 comments

Comments

@guzart
Copy link

commented Jun 15, 2019

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 👏 👏 👏 !

@castwide

This comment has been minimized.

Copy link
Owner

commented Jun 15, 2019

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.

@minkir014

This comment has been minimized.

Copy link

commented Jul 26, 2019

When you intend to implement this feature???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.