Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I provide YARD/RDoc documentation for Ruby keyword arguments? [closed]

Tags:

For a basic Ruby method, I would provide YARD style doc for parameters in the following format.

# @param query [String] The search string to query. # @param options [Hash] Optional search preferences. def search(query, options = {})   # ... end 

With Ruby 2.0, keywords arguments can now be used. However, I'm not sure how to approach that in terms of the YARD documentation.

def search(query, exact_match: false, results_per_page: 10)   # ... end 

How would I document for exact_match and results_per_page in the second scenario? Should I just continue to use the @param keyword, or is there something better?

like image 367
Matt Huggins Avatar asked Mar 08 '14 17:03

Matt Huggins


People also ask

How do you pass keyword arguments in Ruby?

So when you want to pass keyword arguments, you should always use foo(k: expr) or foo(**expr) . If you want to accept keyword arguments, in principle you should always use def foo(k: default) or def foo(k:) or def foo(**kwargs) .

What is keyword arguments in Ruby?

What are keyword arguments? Keyword arguments are a feature in Ruby 2.0 and higher. They're an alternative to positional arguments, and are really similar (conceptually) to passing a hash to a function, but with better and more explicit errors.


1 Answers

YARD recognizes keyword arguments. This should work:

# @param query [String] The search string # @param exact_match [Boolean] whether to do an exact match # @param results_per_page [Integer] number of results def search(query, exact_match: false, results_per_page: 10)   # ... end 
like image 140
Uri Agassi Avatar answered Nov 21 '22 05:11

Uri Agassi