Table Of Contents

Previous topic

Ruby Domain

Next topic

Sample Document

This Page

Reference

The Ruby domain (name rb) provides the following directives for module declarations. Almost all directives are similar to Python’s.

.. rb:module:: name

This directive marks the beginning of the description of a module. This directive can accept nested modules(separated by ::). It does not create content (like e.g. rb:class does).

This directive will also cause an entry in the global module index.

It has platform option, synopsis option and deprecated option as same as py:module.

.. rb:currentmodule:: name

See also

py:currentmodule

The following directives are provided for any where you want:

.. rb:global:: name

Describes global variable which starts with $.

.. rb:exception:: name

Describes an exception class. The signature can, but need not include parentheses with constructor arguments.

The following directives are provided for global and module level contents:

.. rb:function:: name(signature)

Describes a module-level function. Usage of this directive is almost as same as Python’s one.

Note

Ruby has both module function and module method. Module function is standard function like C, Python and so on. Module methods are enbaled when their module is included(Mix-in). This domain express module function as ModuleName.func_name, and module method as ModuleName#func_name. Take care!

See also

.. rb:function:: name

.. rb:const:: name

Describes constant which starts with capital character.

The following directive is provided for module and class contents:

.. rb:method:: name(signature)

Describes a module method and instance method. Usage of this directive is almost as same as Python’s one.

See also

.. py:method:: name .. rb:function:: name

The following directive is provided for module contents:

.. rb:class:: name

Describes a class.

Methods and attributes belonging to the class should be placed in this directive’s body. If they are placed outside, the supplied name should contain the class name so that cross-references still work. Example:

.. rb:class:: Foo
   .. rb:method:: quux()

-- or --

.. rb:class:: Bar

.. rb:method:: Bar#quux()

The first way is the preferred one.

The following directives are provided for class contents:

.. rb:attr_reader:: name
.. rb:attr_writer:: name
.. rb:attr_accessor:: name

Describes an object data attribute. The description should include information about the type of the data to be expected.

.. rb:classmethod:: name(signature)

Like rb:method, but indicates that the method is a class method.

Note

This domain expresses class method as ModuleName.func_name, and instance method as ModuleName#func_name. Take care!

Info field lists

Ruby domain has field lists as same as Python domain except key, keyword.

Cross-referencing Ruby objects

The following roles refer to objects in modules and are possibly hyperlinked if a matching identifier is found:

:rb:mod:

Reference a module; a nested module name may be used(separated by ::).

:rb:func:

Reference a Ruby function; a name with module may be used. The role text needs not include trailing parentheses to enhance readability; they will be added automatically by Sphinx if the add_function_parentheses config value is true (the default).

If you want to refer module function, you should use following style:

:rb:func:`ParentModule::ModuleName.func_name`
:rb:global:

Reference a global variable whose name has $ prefix.

:rb:const:

Reference a constant whose name starts with capital charactor.

:rb:class:

Reference a class; a name with module may be used. In that case, you should use following style:

:rb:class:`ModuleName::ClassName`
:rb:meth:

Reference a method of an object and module. The role text can include the type name and the method name; if it occurs within the description of a type, the type name can be omitted.

This role supports any kind of methods:

:rb:meth:`Module#method`
:rb:meth:`Class#instance_method`
:rb:meth:`Class.class_method`
:rb:attr:

Reference a data attribute of an object.

:rb:exc:

Reference an exception. A dotted name may be used.