How to document Ruby code?

Ruby

Ruby Problem Overview


Are there certain code conventions when documenting ruby code? For example I have the following code snippet:

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

This guess this is okay, but perhaps there are better/superior documentation practices?

Ruby Solutions


Solution 1 - Ruby

You should target your documentation for the RDoc processor, which can find your documentation and generate HTML from it. You've put your comment in the right place for that, but you should have a look at the RDoc documentation to learn about the kinds of tags that RDoc knows how to format. To that end, I'd reformat your comment as follows:

  # 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)

Solution 2 - Ruby

I would highly suggest using RDoc. It is pretty much the standard. It is easy to read the code comments, and it allows you to easily create web-based documentation for your project.

Solution 3 - Ruby

I would suggest getting to know RDoc as is stated. But don't ignore the very popular YARD A Ruby Document tool, as well. A lot of the documentation you will see online for Ruby uses Yard. RVM knows Yard and uses it for generating your documentation on your machine if it is available.

RDoc would still be required, as Yard uses it.

Solution 4 - Ruby

Rails has some API Documentation Guidelines. That's probably a good starting point.

Solution 5 - Ruby

You can also check TomDoc for Ruby - Version 1.0.0-rc1.

http://tomdoc.org/

Solution 6 - Ruby

The canonical is RDoc it is very similar to the one you've posted.

See the sample section on the link I sent you

Solution 7 - Ruby

Here is the documentation for the ruby documentation system (RDOC)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStackedCrookedView Question on Stackoverflow
Solution 1 - RubyKen BloomView Answer on Stackoverflow
Solution 2 - RubyTopher FangioView Answer on Stackoverflow
Solution 3 - RubyvgoffView Answer on Stackoverflow
Solution 4 - RubyHank GayView Answer on Stackoverflow
Solution 5 - RubyonurozgurozkanView Answer on Stackoverflow
Solution 6 - RubyOscarRyzView Answer on Stackoverflow
Solution 7 - RubyjrhicksView Answer on Stackoverflow