# class RDoc::CodeObject

Base class for the RDoc code tree.

We contain the common stuff for contexts (which are containers) and other elements (methods, attributes and so on)

Here’s the tree of the `CodeObject` subclasses:

- RDoc::Context

  - RDoc::TopLevel

  - RDoc::ClassModule

    - RDoc::AnonClass (never used so far)

    - RDoc::NormalClass

    - RDoc::NormalModule

    - RDoc::SingleClass

- RDoc::MethodAttr

  - RDoc::Attr

  - RDoc::AnyMethod

    - RDoc::GhostMethod

    - RDoc::MetaMethod

- RDoc::Alias

- RDoc::Constant

- RDoc::Require

- RDoc::Mixin

  - RDoc::Include

  - RDoc::Extend

### Attributes

comment [R]

Our comment

document_children [R]

Do we document our children?

document_self [R]

Do we document ourselves?

done_documenting [R]

Are we done documenting (ie, did we come across a :enddoc:)?

file [R]

Which file this code object was defined in

force_documentation [R]

Force documentation of this `CodeObject`

line [RW]

Line in `file` where this `CodeObject` was defined

metadata [R]

`Hash` of arbitrary metadata for this `CodeObject`

mixin_from [RW]

When mixed-in to a class, this points to the Context in which it was originally defined.

parent [W]

Sets the parent `CodeObject`

received_nodoc [R]

Did we ever receive a `:nodoc:` directive?

section [W]

Set the section this `CodeObject` is in

store [R]

The `RDoc::Store` for this object.

### Public Class Methods

new ()
Source

    # File lib/rdoc/code_object.rb, line 101
    def initialize
      @metadata         = {}
      @comment          = ''
      @parent           = nil
      @parent_name      = nil # for loading
      @parent_class     = nil # for loading
      @section          = nil
      @section_title    = nil # for loading
      @file             = nil
      @full_name        = nil
      @store            = nil
      @track_visibility = true
      @mixin_from       = nil

      initialize_visibility
    end

Creates a new `CodeObject` that will document itself and its children

### Public Instance Methods

comment= (comment)
Source

    # File lib/rdoc/code_object.rb, line 135
    def comment=(comment)
      @comment = case comment
                 when NilClass               then ''
                 when RDoc::Comment          then comment.normalize
                 else
                   if comment and not comment.empty? then
                     normalize_comment comment
                   else
                     # HACK correct fix is to have #initialize create @comment
                     #      with the correct encoding
                     if String === @comment and @comment.empty? then
                       @comment = RDoc::Encoding.change_encoding @comment, comment.encoding
                     end
                     @comment
                   end
                 end
    end

Replaces our comment with `comment`, unless it is empty.

display? ()
Source

    # File lib/rdoc/code_object.rb, line 162
    def display?
      @document_self and not @ignored and
        (documented? or not @suppressed)
    end

Should this `CodeObject` be displayed in output?

A code object should be displayed if:

- The item didn’t have a nodoc or wasn’t in a container that had nodoc

- The item wasn’t ignored

- The item has documentation and was not suppressed

document_children= (document_children)
Source

    # File lib/rdoc/code_object.rb, line 171
    def document_children=(document_children)
      return unless @track_visibility

      @document_children = document_children unless @done_documenting
    end

Enables or disables documentation of this CodeObject’s children unless it has been turned off by :enddoc:

document_self= (document_self)
Source

    # File lib/rdoc/code_object.rb, line 182
    def document_self=(document_self)
      return unless @track_visibility
      return if @done_documenting

      @document_self = document_self
      @received_nodoc = true if document_self.nil?
    end

Enables or disables documentation of this `CodeObject` unless it has been turned off by :enddoc:. If the argument is `nil` it means the documentation is turned off by `:nodoc:`.

documented? ()
Source

    # File lib/rdoc/code_object.rb, line 193
    def documented?
      @received_nodoc or !@comment.empty?
    end

Does this object have a comment with content or is `received_nodoc` true?

done_documenting= (value)
Source

    # File lib/rdoc/code_object.rb, line 206
    def done_documenting=(value)
      return unless @track_visibility
      @done_documenting  = value
      @document_self     = !value
      @document_children = @document_self
    end

Turns documentation on/off, and turns on/off `document_self` and `document_children`.

Once documentation has been turned off (by `:enddoc:`), the object will refuse to turn `document_self` or `document_children` on, so `:doc:` and `:start_doc:` directives will have no effect in the current file.

file_name ()
Source

    # File lib/rdoc/code_object.rb, line 218
    def file_name
      return unless @file

      @file.absolute_name
    end

`File` name where this `CodeObject` was found.

See also RDoc::Context#in_files

force_documentation= (value)
Source

    # File lib/rdoc/code_object.rb, line 230
    def force_documentation=(value)
      @force_documentation = value unless @done_documenting
    end

Force the documentation of this object unless documentation has been turned off by :enddoc:

full_name= (full_name)
Source

    # File lib/rdoc/code_object.rb, line 239
    def full_name=(full_name)
      @full_name = full_name
    end

Sets the full_name overriding any computed full name.

Set to `nil` to clear RDoc’s cached value

ignore ()
Source

    # File lib/rdoc/code_object.rb, line 259
    def ignore
      return unless @track_visibility

      @ignored = true

      stop_doc
    end

Use this to ignore a `CodeObject` and all its children until found again (`record_location` is called). An ignored item will not be displayed in documentation.

See github issue #55

The ignored status is temporary in order to allow implementation details to be hidden. At the end of processing a file RDoc allows all classes and modules to add new documentation to previously created classes.

If a class was ignored (via stopdoc) then reopened later with additional documentation it should be displayed. If a class was ignored and never reopened it should not be displayed. The ignore flag allows this to occur.

ignored? ()
Source

    # File lib/rdoc/code_object.rb, line 272
    def ignored?
      @ignored
    end

Has this class been ignored?

See also `ignore`

options ()
Source

    # File lib/rdoc/code_object.rb, line 282
    def options
      @store&.options || RDoc::Options.new
    end

The options instance from the store this `CodeObject` is attached to, or a default options instance if the `CodeObject` is not attached.

This is used by Text#snippet

parent ()
Source

    # File lib/rdoc/code_object.rb, line 290
    def parent
      return @parent if @parent
      return nil unless @parent_name

      if @parent_class == RDoc::TopLevel then
        @parent = @store.add_file @parent_name
      else
        @parent = @store.find_class_or_module @parent_name

        return @parent if @parent

        begin
          @parent = @store.load_class @parent_name
        rescue RDoc::Store::MissingFileError
          nil
        end
      end
    end

Our parent `CodeObject`. The parent may be missing for classes loaded from legacy RI data stores.

parent_name ()
Source

    # File lib/rdoc/code_object.rb, line 312
    def parent_name
      @parent ? @parent.full_name : '(unknown)'
    end

Name of our parent

record_location (top_level)
Source

    # File lib/rdoc/code_object.rb, line 319
    def record_location(top_level)
      @ignored    = false
      @suppressed = false
      @file       = top_level
    end

Records the RDoc::TopLevel (file) where this code object was defined

section ()
Source

    # File lib/rdoc/code_object.rb, line 329
    def section
      return @section if @section

      @section = parent.add_section @section_title if parent
    end

The section this `CodeObject` is in. Sections allow grouping of constants, attributes and methods inside a class or module.

start_doc ()
Source

    # File lib/rdoc/code_object.rb, line 339
    def start_doc
      return if @done_documenting

      @document_self = true
      @document_children = true
      @ignored    = false
      @suppressed = false
    end

Enable capture of documentation unless documentation has been turned off by :enddoc:

stop_doc ()
Source

    # File lib/rdoc/code_object.rb, line 351
    def stop_doc
      return unless @track_visibility

      @document_self = false
      @document_children = false
    end

Disable capture of documentation

store= (store)
Source

    # File lib/rdoc/code_object.rb, line 361
    def store=(store)
      @store = store

      return unless @track_visibility

      if :nodoc == options.visibility then
        initialize_visibility
        @track_visibility = false
      end
    end

Sets the `store` that contains this `CodeObject`

suppress ()
Source

    # File lib/rdoc/code_object.rb, line 378
    def suppress
      return unless @track_visibility

      @suppressed = true

      stop_doc
    end

Use this to suppress a `CodeObject` and all its children until the next file it is seen in or documentation is discovered. A suppressed item with documentation will be displayed while an ignored item with documentation may not be displayed.

suppressed? ()
Source

    # File lib/rdoc/code_object.rb, line 391
    def suppressed?
      @suppressed
    end

Has this class been suppressed?

See also `suppress`