What is the equivalent of a Python docstring in Ruby?
In Python, you can access an object's docstring by using obj.__doc__. What is the equivalent action 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.
I don't believe ruby supports this.
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.