In Python, you can access an object's docstring by using obj.__doc__
. What is the equivalent action in Ruby?
A Python docstring is a string used to document a Python module, class, function or method, so programmers can understand what it does without having to read the details of the implementation. Also, it is a common practice to generate online (html) documentation automatically from docstrings.
As mentioned above, Python docstrings are strings used right after the definition of a function, method, class, or module (like in Example 1). They are used to document our code. We can access these docstrings using the __doc__ attribute.
Docstrings can be seen when calling a function from within python, but outside the module, but main() is usually only called from the command line (where the docstring is not accessible). The idea of main() should be well enough understood that it need no documentation.
The docstring for a module should generally list the classes, exceptions and functions (and any other objects) that are exported by the module, with a one-line summary of each. (These summaries generally give less detail than the summary line in the object's docstring.)
Ruby does not have a Python __doc__
equivalent. They often use Rdoc Format for documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With