RDoc, Yard, TomDoc – I still don't really know how to document Ruby (gem) code. Please help. Do you know a definitive guide?

#ruby #rdoc

@ahx i also recently had this thought and went with yard (is there really an alternative?) I’m pleased with the results and found the type hints to be very satisfying (especially if your editor can surface them) https://rubydoc.info/gems/operatic/Operatic / https://github.com/benpickles/operatic/blob/main/lib/operatic.rb this page was useful https://rubydoc.info/gems/yard/file/docs/Tags.md
Module: Operatic — Documentation for operatic (0.7.0)

@benpickles Thanks for the links Ben. One clear advantage that Yard has for me over RDoc is that it has a documented (!) way of describing complex returns types like Hash<String> or Array<Thing>.
@ahx i'm really hopeful that we can converge on a single method for succinct inline typing (like yard’s) because it’s simple and easy to add and the subtle/not-subtle benefits have a broad positive impact

@ahx I think it's down to personal preference.

Initially I used RDoc for the Mocha gem [1], because it was the only option at the time. However, I switched to Yard about 12 years ago, because it provides richer information about the code and I'm still _fairly_ happy with it.

I hadn't seen TomDoc, but at first glance it looks interesting.

[1]: https://github.com/freerange/mocha

GitHub - freerange/mocha: A mocking and stubbing library for Ruby

A mocking and stubbing library for Ruby. Contribute to freerange/mocha development by creating an account on GitHub.

GitHub

@ahx One consideration might be if you want to rely on one of the sites that automatically generate docs for gems, e.g. https://rubydoc.info/. However, since I publish my own docs [1], this isn't an issue for me.

[1]: https://mocha.jamesmead.org/

RubyDoc.info: Documenting RubyGems, Stdlib, and GitHub Projects

@ahx Also I think gem specification [1] still assumes you're using RDoc, although I seem to remember that Yard is backwardly compatible with RDoc...?

[1]: https://guides.rubygems.org/specification-reference/

Specification Reference - RubyGems Guides

@ahx I use Yard. Mostly because I want to use Markdown and I like its tag system. Default template looks fine, too.