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, for example:
# For example, a square or circle.
class Shape
# A horizontal position.
def x
end
# A vertical position.
def y
end
end
I don't believe ruby supports this.
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 here
class MyClass
end
# 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.