【发布时间】:2010-12-13 11:31:30
【问题描述】:
在记录 ruby 代码时是否有某些代码约定?例如我有以下代码sn-p:
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
这个猜测是可以的,但也许有更好/更好的文档实践?
【问题讨论】:
-
shop.oreilly.com/product/9780596516178.do 在源代码中有一个很好的小例子。参见第 2 章列表。这就像这里的答案。我玩过 rdoc 只是为了显示源代码。您可以将文件扩展名设置为 my_code.rb 到 my_code.rb.txt,然后在其上运行 rdoc。 > rdoc my_code.rb.txt 那么类和模块就无关紧要了,因为 rdoc 无论如何都会为它渲染 html。玩得开心。
标签: ruby