本文根据 Devhints / Rdoc 翻译。代码示例及版本范围沿用原文。
基本 RDoc 格式
# Foo.
#
# @example
#
# y
# g
#
# @param [String] param_name The xx and xx.
#
# @see https://example.com/
#
# @return [true] if so
哈希参数
# @param [Hash] opts the options to create a message with.
# @option opts [String] :subject The subject
# @option opts [String] :from ('nobody') From address
# @option opts [String] :to Recipient email
# @option opts [String] :body ('') The email's body
参数类型
# @param (see User#initialize)
# @param [OptionParser] opts the option parser object
# @param [Array<String>] args the arguments passed from input. This
# array will be modified.
# @param [Array<String, Symbol>] list the list of strings and symbols.
# @param [Hash<Symbol, String>] a hash with symbol keys and string values
#
# The options parsed out of the commandline.
# Default options are:
# :format => :dot
异常
# @raise [AccountBalanceError] if the account does not have
# sufficient funds to perform the transaction
行内
*bold*
_emphasized_
+code+
{ObjectName#method optional title}
{Class::CONSTANT My constant's title}
{#method_inside_current_namespace}
https://www.example.com/
See Models::User@Examples
{Google}[https://google.com/]
跳过
def input # :nodoc:
module MyModule # :nodoc: all
定义列表
# == Definition lists
#
# list:: hi.
# +foo+:: parameterized
# == Definition lists
# [foo] also
# [bar] like this
返回类型
# @return [String]
# @return [String, nil] the name
调用序列 (Callseq)
# :call-seq:
# ARGF.readlines(sep=$/) -> array
# ARGF.readlines(limit) -> array
# ARGF.readlines(sep, limit) -> array
#
# ARGF.to_a(sep=$/) -> array
# ARGF.to_a(limit) -> array
# ARGF.to_a(sep, limit) -> array
类别
# :category: Utilities
章节
# :section: Expiry methods
# methods relating to expiring
def expire!
def expired?
...
使用 TomDoc
# :markup: TomDoc
将其放置在文件开头。