This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

RDoc & YARD Documentation Cheatsheet

A quick reference guide for RDoc and YARD: documenting Ruby classes, methods, parameters, return types, code examples, and formatting directives.

· Published

RDoc and YARD are standard documentation tools for Ruby, parsing source comments to generate browsable API documentation.

Method Documentation Pattern

# Calculates total order price after applying discount vouchers.
#
# @example Applying a seasonal voucher
#   calculator = PriceCalculator.new(order)
#   calculator.final_total(voucher: 'SUMMER20') #=> 80.0
#
# @param voucher [String, nil] The voucher code to apply.
# @param tax_rate [Float] Applicable sales tax rate (default: 0.1).
# @return [Float] Total rounded price in USD.
# @raise [InvalidVoucherError] If voucher is expired or unrecognized.
def final_total(voucher: nil, tax_rate: 0.1)
  # ...
end

Inline Markup Formatting

*bold text*
_emphasized text_
+code or monospace+

{ClassName}          # Link to class
{ClassName#method}   # Link to instance method
{ClassName.method}   # Link to class method

Special Directives

# Hide method or class from generated documentation
def internal_secret # :nodoc:
end

# Document specific call sequence signature
# :call-seq:
#   format(val) -> String
#   format(val, options) -> String

References

Related topics