What is the equivalent of a Python docstring in Ruby? What is the equivalent of a Python docstring in Ruby? python python

What is the equivalent of a Python docstring in Ruby?


Ruby does not have a Python __doc__ equivalent. They often use Rdoc Format for documentation.


Unfortunatelly Ruby does not have any Python like built-in docstrings.

RDoc looks terrible. RDoc is designed to be processed into HTML format and read in the we browser. It's not plain text. Who likes reading HTML-like source code? YARD is better. There is also TomDoc which use just plain text. But none of them compare to Pythonic docstrings which e.g. allow for simple autocompletion from any python console and do need to use any processing tool.


It's easier to document in Ruby using Yard, which supports different tags like :NODOC:

To document your code with Yard, just write the comment above your code.

# MyClass.new(...) some comment hereclass MyClassend# foo("bar")def foo(bar = nil)end

then run yard on the current working directory of your project, this will generate the $PWD/doc directory for you with a nice set of documentations.