RDoc und YARD sind Standard-Dokumentationstools für Ruby, die Quellkommentare analysieren, um API-Dokumentationen zu erstellen.
Muster für Methodendokumentation
# 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-Formatierung
*bold text*
_emphasized text_
+code or monospace+
{ClassName} # Link zur Klasse
{ClassName#method} # Link zur Instanzmethode
{ClassName.method} # Link zur Klassenmethode
Spezielle Direktiven
# Methode oder Klasse in generierter Dokumentation ausblenden
def internal_secret # :nodoc:
end
# Bestimmte Aufrufsignatur dokumentieren
# :call-seq:
# format(val) -> String
# format(val, options) -> String