在记录红宝石代码时是否有某些代码约定?例如,我有以下代码片段:
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。玩得开心。
—
Douglas G. Allen