在记录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.你已经把你的 comments 放在了正确的地方,但是你应该看看RDoc documentation个标签,了解RDoc知道如何格式化标签的种类.为此,我将你的 comments 改写如下:

  # 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)

Ruby相关问答推荐

Ruby类构造函数使用`()`而不是`. new()`

应用 ransack 日期字段过滤器后,相同的输出票证重复而不是一张

无法解析音频文件 track1.m4a

Ruby 中的内联注释

如何从 url 获取文件扩展名?

在 Ruby 中导出环境变量

如何在 Ruby 的 RestClient gem 中设置超时?

Ruby 中的 STDIN 和 $stdin 有什么区别?

创建一个哈希值作为数组和默认值作为空数组

osx bash上的树命令

查明 IP 是否在 IP 范围内

Ruby 中的 Object 和 BasicObject 有什么区别?

如何用 Ruby 覆盖 shell 中的打印行?

什么时候在 Ruby 中使用 Struct 比使用 Hash 更好?

查找两个数组之间的共同值

如何在 ruby​​ 中针对正则表达式测试整个字符串?

Ruby:除非与如果不是

将 CSV 文件转换为哈希数组

纯 Ruby 并发哈希

如何使用#{variable}在Ruby中格式化带有浮点数的字符串?