frozen_string_literal: true

ClassModule is the base class for objects representing either a class or a module.

Methods
A
C
D
E
F
M
N
P
R
S
T
U
Constants
MARSHAL_VERSION = 3
 
1

RDoc 3.7

  • Added visibility, singleton and file to attributes

  • Added file to constants

  • Added file to includes

  • Added file to methods

2

RDoc 3.13

  • Added extends

3

RDoc 4.0

  • Added sections

  • Added in_files

  • Added parent name

  • Complete Constant dump

Attributes
[RW] comment_location

Comment and the location it came from. Use add_comment to add comments

[RW] constant_aliases

Constants that are aliases for this class or module

[RW] is_alias_for

Class or module this constant is an alias for

Class Public methods
from_module(class_type, mod)

Return a RDoc::ClassModule of class class_type that is a copy of module module. Used to promote modules to classes.

# File lib/rdoc/class_module.rb, line 50
def self.from_module class_type, mod
  klass = class_type.new mod.name

  mod.comment_location.each do |comment, location|
    klass.add_comment comment, location
  end

  klass.parent = mod.parent
  klass.section = mod.section
  klass.viewer = mod.viewer

  klass.attributes.concat mod.attributes
  klass.method_list.concat mod.method_list
  klass.aliases.concat mod.aliases
  klass.external_aliases.concat mod.external_aliases
  klass.constants.concat mod.constants
  klass.includes.concat mod.includes
  klass.extends.concat mod.extends

  klass.methods_hash.update mod.methods_hash
  klass.constants_hash.update mod.constants_hash

  klass.current_section = mod.current_section
  klass.in_files.concat mod.in_files
  klass.sections.concat mod.sections
  klass.unmatched_alias_lists = mod.unmatched_alias_lists
  klass.current_section = mod.current_section
  klass.visibility = mod.visibility

  klass.classes_hash.update mod.classes_hash
  klass.modules_hash.update mod.modules_hash
  klass.metadata.update mod.metadata

  klass.document_self = mod.received_nodoc ? nil : mod.document_self
  klass.document_children = mod.document_children
  klass.force_documentation = mod.force_documentation
  klass.done_documenting = mod.done_documenting

  # update the parent of all children

  (klass.attributes +
   klass.method_list +
   klass.aliases +
   klass.external_aliases +
   klass.constants +
   klass.includes +
   klass.extends +
   klass.classes +
   klass.modules).each do |obj|
    obj.parent = klass
    obj.full_name = nil
  end

  klass
end
new(name, superclass = nil)

Creates a new ClassModule with name with optional superclass

This is a constructor for subclasses, and must never be called directly.

# File lib/rdoc/class_module.rb, line 111
def initialize(name, superclass = nil)
  @constant_aliases = []
  @diagram          = nil
  @is_alias_for     = nil
  @name             = name
  @superclass       = superclass
  @comment_location = [] # [[comment, location]]

  super()
end
Instance Public methods
add_comment(comment, location)

Adds comment to this ClassModule's list of comments at location. This method is preferred over comment= since it allows ri data to be updated across multiple runs.

# File lib/rdoc/class_module.rb, line 127
def add_comment comment, location
  return unless document_self

  original = comment

  comment = case comment
            when RDoc::Comment then
              comment.normalize
            else
              normalize_comment comment
            end

  if location.parser == RDoc::Parser::C
    @comment_location.delete_if { |(_, l)| l == location }
  end

  @comment_location << [comment, location]

  self.comment = original
end
ancestors()

Ancestors list for this ClassModule: the list of included modules (classes will add their superclass if any).

Returns the included classes or modules, not the includes themselves. The returned values are either String or RDoc::NormalModule instances (see RDoc::Mixin#module).

The values are returned in reverse order of their inclusion, which is the order suitable for searching methods/attributes in the ancestors. The superclass, if any, comes last.

Also aliased as: direct_ancestors
# File lib/rdoc/class_module.rb, line 171
def ancestors
  includes.map { |i| i.module }.reverse
end
aref()

HTML fragment reference for this module or class. See #aref and #aref

# File lib/rdoc/class_module.rb, line 183
def aref
  "#{aref_prefix}-#{full_name}"
end
clear_comment()

Clears the comment. Used by the Ruby parser.

# File lib/rdoc/class_module.rb, line 195
def clear_comment
  @comment = ''
end
complete(min_visibility)

Prepares this ClassModule for use by a generator.

See RDoc::Store#complete

# File lib/rdoc/class_module.rb, line 223
def complete min_visibility
  update_aliases
  remove_nodoc_children
  update_includes
  remove_invisible min_visibility
end
direct_ancestors()

Ancestors of this class or module only

Alias for: ancestors
document_self_or_methods()

Does this ClassModule or any of its methods have document_self set?

# File lib/rdoc/class_module.rb, line 233
def document_self_or_methods
  document_self || method_list.any?{ |m| m.document_self }
end
documented?()

Does this class or module have a comment with content or is received_nodoc true?

# File lib/rdoc/class_module.rb, line 241
def documented?
  return true if @received_nodoc
  return false if @comment_location.empty?
  @comment_location.any? { |comment, _| not comment.empty? }
end
each_ancestor()

Iterates the ancestors of this class or module for which an RDoc::ClassModule exists.

# File lib/rdoc/class_module.rb, line 251
def each_ancestor # :yields: module
  return enum_for __method__ unless block_given?

  ancestors.each do |mod|
    next if String === mod
    next if self == mod
    yield mod
  end
end
find_ancestor_local_symbol(symbol)

Looks for a symbol in the ancestors. See Context#find_local_symbol.

# File lib/rdoc/class_module.rb, line 264
def find_ancestor_local_symbol symbol
  each_ancestor do |m|
    res = m.find_local_symbol(symbol)
    return res if res
  end

  nil
end
find_class_named(name)

Finds a class or module with name in this namespace or its descendants

# File lib/rdoc/class_module.rb, line 276
def find_class_named name
  return self if full_name == name
  return self if @name == name

  @classes.values.find do |klass|
    next if klass == self
    klass.find_class_named name
  end
end
full_name()

Return the fully qualified name of this class or module

# File lib/rdoc/class_module.rb, line 289
def full_name
  @full_name ||= if RDoc::ClassModule === parent then
                   "#{parent.full_name}::#{@name}"
                 else
                   @name
                 end
end
merge(class_module)

Merges class_module into this ClassModule.

The data in class_module is preferred over the receiver.

# File lib/rdoc/class_module.rb, line 435
def merge class_module
  @parent      = class_module.parent
  @parent_name = class_module.parent_name

  other_document = parse class_module.comment_location

  if other_document then
    document = parse @comment_location

    document = document.merge other_document

    @comment = @comment_location = document
  end

  cm = class_module
  other_files = cm.in_files

  merge_collections attributes, cm.attributes, other_files do |add, attr|
    if add then
      add_attribute attr
    else
      @attributes.delete attr
      @methods_hash.delete attr.pretty_name
    end
  end

  merge_collections constants, cm.constants, other_files do |add, const|
    if add then
      add_constant const
    else
      @constants.delete const
      @constants_hash.delete const.name
    end
  end

  merge_collections includes, cm.includes, other_files do |add, incl|
    if add then
      add_include