Search code examples
rubyyard

Mark a parameter as optional (or has a default) with YARD


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

Solution

  • 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")