Search code examples
pythonruby-on-railsrubydocumentationlanguage-comparisons

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?


Solution

  • 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