在记录 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
我想这样做也可以,但是可能有更好/更优秀的文档编写实践吗?