Вопрос

I'm using YARD to document my code. I have a method that has an optional parameter with a default value. How do I notate that the parameter is optional and has a default value?

Example:

# Squares a number
# 
# @param the number to square
def square_a_number(number = 2)
  number * number
end
Это было полезно?

Решение

To mark a parameter is option you can simply use @param optional (see http://rubydoc.info/docs/yard/file/docs/Tags.md). As far as I know, there's now way to notate a default value; you're probably best to put it in the description ("the number to square, defaults to 2")

Другие советы

YARD now supports param defaults automatically.

YARD automatically figures out the default value based on the method definition. Sweedish!

For example, the following code documentation will produce the subsequent YARD doc:

Code Documentation

# Squares a number.
# 
# @param number [Integer] The number to square.
#
def square_a_number(number = 2)
  number * number
end

Resulting YARD Documentation

Parameters:
  number (Integer optional) (defaults to: 2)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top