26

对于基本的 Ruby 方法,我将为以下格式的参数提供 YARD 样式的文档。

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

在 Ruby 2.0 中,现在可以使用关键字参数。但是,我不确定如何根据 YARD 文档来解决这个问题。

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

在第二种情况下,exact_match我将如何记录?results_per_page我应该继续使用@param关键字,还是有更好的方法?

4

1 回答 1

30

YARD 识别关键字参数。这应该有效:

# @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
于 2014-03-08T18:34:33.273 回答