记录 ruby 代码时是否有某些代码约定?例如,我有以下代码片段:
require 'open3' module ProcessUtils # Runs a subprocess and applies handlers for stdout and stderr # Params: # - command: command line string to be executed by the system # - outhandler: proc object that takes a pipe object as first and only param (may be nil) # - errhandler: proc object that takes a pipe object as first and only param (may be nil) def execute_and_handle(command, outhandler, errhandler) Open3.popen3(command) do |_, stdout, stderr| if (outhandler) outhandler.call(stdout) end if (errhandler) errhandler.call(stderr) end end end end
这个猜测没关系,但也许有更好/更好的文档实践?
您应该将您的文档定位为 RDoc 处理器,它可以找到您的文档并从中生成 HTML。为此,您已将评论放在正确的位置,但您应该查看RDoc 文档以了解 RDoc 知道如何格式化的标记类型。为此,我将您的评论重新格式化如下:
# Runs a subprocess and applies handlers for stdout and stderr # Params: # +command+:: command line string to be executed by the system # +outhandler+:: +Proc+ object that takes a pipe object as first and only param (may be nil) # +errhandler+:: +Proc+ object that takes a pipe object as first and only param (may be nil)