Có quy ước mã nào đó khi viết mã ruby không? Ví dụ: tôi có đoạn mã sau:Làm thế nào để tài liệu mã 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
Điều này có thể đoán được, nhưng có lẽ có thực tiễn tốt hơn/cao hơn?
http://shop.oreilly.com/product/9780596516178.do có một ví dụ nhỏ về mã nguồn. Xem trong danh sách chương 2. Nó giống như câu trả lời ở đây. Tôi đã chơi với rdoc chỉ để hiển thị mã nguồn. Bạn có thể làm cho phần mở rộng tập tin của bạn một cái gì đó như my_code.rb để my_code.rb.txt và sau đó chạy rdoc trên đó. > rdoc my_code.rb.txt sau đó nó sẽ không quan trọng về các lớp học và các mô-đun bởi vì rdoc sẽ làm cho html cho nó anyway. Hãy vui vẻ với nó. –