ルビコードを文書化する際に特定のコード規約がありますか?たとえば、私は次のコードスニペットを持っています: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
これは大丈夫ですが、おそらくより優れた/優れたドキュメントの実践がありますか?
http://shop.oreilly.com/product/9780596516178.doには、ソースコード内に少しだけいい例があります。第2章のリストを見てください。それはここの答えのようなものです。私はrdocでソースコードを表示しています。ファイル拡張子をmy_code.rbのようにmy_code.rb.txtにしてから、rdocを実行することができます。 > rdoc my_code.rb.txtそれでは、rdocはhtmlをレンダリングするので、クラスとモジュールについては問題になりません。それを楽しみましょう。 –