Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 987
parzival Avatar asked Feb 15 '11 16:02

parzival


People also ask

What is a docstring in Python?

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.

What is docstring in Python examples?

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.

Do you need a docstring for Main?

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.

What do you write in a module docstring?

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.)


1 Answers

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

like image 188
Tarantula Avatar answered Sep 22 '22 07:09

Tarantula