Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

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 
like image 622
brainimus Avatar asked Oct 21 '11 16:10

brainimus


People also ask

What is default or optional parameter?

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.

How do you make a parameter optional in VBA?

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.

What are optional parameters are added?

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.


Video Answer


1 Answers

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) 
like image 92
Joshua Pinter Avatar answered Oct 04 '22 04:10

Joshua Pinter