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
A parameter with a default value, is often known as an "optional parameter". From the example above, country is an optional parameter and "Norway" is the default value.
The optional parameter(s) must be at the end of the parameter list. The IsMissing function will work only with parameters declared as Variant . It will return False when used with any other data type. User defined types (UTDs) cannot be optional parameters.
Optional Parameters are parameters that can be specified, but are not required. This allows for functions that are more customizable, without requiring parameters that many users will not need.
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:
# Squares a number. # # @param number [Integer] The number to square. # def square_a_number(number = 2) number * number end
Parameters: number (Integer optional) (defaults to: 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With