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

Question: How to document methods that accept argument forwarding? #1362

Open
synthead opened this issue Nov 23, 2020 · 1 comment
Open

Question: How to document methods that accept argument forwarding? #1362

synthead opened this issue Nov 23, 2020 · 1 comment
Labels

Comments

@synthead
Copy link

Ruby 2.7 introduces argument forwarding, which looks like this:

def accept_any_args(...)
  call_with_any_args(...)
end

If argument forwarding is used with YARD, one might attempt to document their methods like this:

# Inspects some options.
#
# @param [Hash] options Options to inspect.
# @return [String] Inspected object.
def my_method(...)
  private_method(...)
end

private

def private_method(**options)
  options.inspect
end

However, when yardoc is ran with the above code, it raises this warning:

[warn]: @param tag has unknown parameter name: options 

How should the above code be documented with YARD?

@lsegal
Copy link
Owner

lsegal commented Dec 27, 2020

The general approach here would be the same as the case where you have a *args or **kwargs method-- you would use @overload to define a synthesized method signature:

# @overload my_method(a, b)
#   @param a [String] the first parameter
#   @param b [Boolean] the second parameter
def my_method(...) = other(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants