In Files

  • rdoc/code_objects.rb

Files

Class/Module Index [+]

Quicksearch

RDoc::Context

A Context is something that can hold modules, classes, methods, attributes, aliases, requires, and includes. Classes, modules, and files are all Contexts.

Attributes

aliases[R]
attributes[R]
constants[R]
current_section[R]
in_files[R]
includes[R]
method_list[R]
name[R]
requires[R]
sections[R]
visibility[R]

Public Class Methods

new() click to toggle source
 
               # File rdoc/code_objects.rb, line 191
def initialize
  super

  @in_files = []

  @name    ||= "unknown"
  @comment ||= ""
  @parent  = nil
  @visibility = :public

  @current_section = Section.new(nil, nil)
  @sections = [ @current_section ]

  initialize_methods_etc
  initialize_classes_and_modules
end
            

Public Instance Methods

<=>(other) click to toggle source

allow us to sort modules by name

 
               # File rdoc/code_objects.rb, line 474
def <=>(other)
  name <=> other.name
end
            
add_alias(an_alias) click to toggle source
 
               # File rdoc/code_objects.rb, line 344
def add_alias(an_alias)
  meth = find_instance_method_named(an_alias.old_name)

  if meth then
    add_alias_impl(an_alias, meth)
  else
    add_to(@aliases, an_alias)
    unmatched_alias_list = @unmatched_alias_lists[an_alias.old_name] ||= []
    unmatched_alias_list.push(an_alias)
  end

  an_alias
end
            
add_alias_impl(an_alias, meth) click to toggle source
 
               # File rdoc/code_objects.rb, line 334
def add_alias_impl(an_alias, meth)
  new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
  new_meth.is_alias_for = meth
  new_meth.singleton    = meth.singleton
  new_meth.params       = meth.params
  new_meth.comment = "Alias for \##{meth.name}"
  meth.add_alias(new_meth)
  add_method(new_meth)
end
            
add_attribute(an_attribute) click to toggle source
 
               # File rdoc/code_objects.rb, line 330
def add_attribute(an_attribute)
  add_to(@attributes, an_attribute)
end
            
add_class(class_type, name, superclass) click to toggle source
 
               # File rdoc/code_objects.rb, line 290
def add_class(class_type, name, superclass)
  klass = add_class_or_module @classes, class_type, name, superclass

  #
  # If the parser encounters Container::Item before encountering
  # Container, then it assumes that Container is a module.  This
  # may not be the case, so remove Container from the module list
  # if present and transfer any contained classes and modules to
  # the new class.
  #
  mod = @modules.delete(name)

  if mod then
    klass.classes_hash.update(mod.classes_hash)
    klass.modules_hash.update(mod.modules_hash)
    klass.method_list.concat(mod.method_list)
  end

  return klass
end
            
add_class_or_module(collection, class_type, name, superclass=nil) click to toggle source
 
               # File rdoc/code_objects.rb, line 375
    def add_class_or_module(collection, class_type, name, superclass=nil)
      cls = collection[name]

      if cls then
        cls.superclass = superclass unless cls.module?
        puts "Reusing class/module #{name}" if $DEBUG_RDOC
      else
        cls = class_type.new(name, superclass)
#        collection[name] = cls if @document_self  && !@done_documenting
        collection[name] = cls if !@done_documenting
        cls.parent = self
        cls.section = @current_section
      end
      cls
    end
            
add_constant(const) click to toggle source
 
               # File rdoc/code_objects.rb, line 362
def add_constant(const)
  add_to(@constants, const)
end
            
add_include(an_include) click to toggle source
 
               # File rdoc/code_objects.rb, line 358
def add_include(an_include)
  add_to(@includes, an_include)
end
            
add_method(a_method) click to toggle source
 
               # File rdoc/code_objects.rb, line 315
def add_method(a_method)
  a_method.visibility = @visibility
  add_to(@method_list, a_method)

  unmatched_alias_list = @unmatched_alias_lists[a_method.name]
  if unmatched_alias_list then
    unmatched_alias_list.each do |unmatched_alias|
      add_alias_impl unmatched_alias, a_method
      @aliases.delete unmatched_alias
    end

    @unmatched_alias_lists.delete a_method.name
  end
end
            
add_module(class_type, name) click to toggle source
 
               # File rdoc/code_objects.rb, line 311
def add_module(class_type, name)
  add_class_or_module(@modules, class_type, name, nil)
end
            
add_require(a_require) click to toggle source

Requires always get added to the top-level (file) context

 
               # File rdoc/code_objects.rb, line 367
def add_require(a_require)
  if TopLevel === self then
    add_to @requires, a_require
  else
    parent.add_require a_require
  end
end
            
add_to(array, thing) click to toggle source
 
               # File rdoc/code_objects.rb, line 391
def add_to(array, thing)
  array << thing if @document_self and not @done_documenting
  thing.parent = self
  thing.section = @current_section
end
            
classes() click to toggle source

map the class hash to an array externally

 
               # File rdoc/code_objects.rb, line 211
def classes
  @classes.values
end
            
defined_in?(file) click to toggle source

Return true if at least part of this thing was defined in file

 
               # File rdoc/code_objects.rb, line 286
def defined_in?(file)
  @in_files.include?(file)
end
            
each_attribute() click to toggle source
 
               # File rdoc/code_objects.rb, line 456
def each_attribute 
  @attributes.each {|a| yield a}
end
            
each_classmodule() click to toggle source

Iterate over all the classes and modules in this object

 
               # File rdoc/code_objects.rb, line 447
def each_classmodule
  @modules.each_value {|m| yield m}
  @classes.each_value {|c| yield c}
end
            
each_constant() click to toggle source
 
               # File rdoc/code_objects.rb, line 460
def each_constant
  @constants.each {|c| yield c}
end
            
each_method() click to toggle source
 
               # File rdoc/code_objects.rb, line 452
def each_method
  @method_list.each {|m| yield m}
end
            
find_enclosing_module_named(name) click to toggle source

find a module at a higher scope

 
               # File rdoc/code_objects.rb, line 440
def find_enclosing_module_named(name)
  parent && parent.find_module_named(name)
end
            
find_local_symbol(symbol) click to toggle source
 
               # File rdoc/code_objects.rb, line 529
def find_local_symbol(symbol)
  res = find_method_named(symbol) ||
        find_constant_named(symbol) ||
        find_attribute_named(symbol) ||
        find_module_named(symbol) ||
        find_file_named(symbol)
end
            
find_module_named(name) click to toggle source

Find a named module

 
               # File rdoc/code_objects.rb, line 429
def find_module_named(name)
  # First check the enclosed modules, then check the module itself,
  # then check the enclosing modules (this mirrors the check done by
  # the Ruby parser)
  res = @modules[name] || @classes[name]
  return res if res
  return self if self.name == name
  find_enclosing_module_named(name)
end
            
find_symbol(symbol, method = nil) click to toggle source

Look up symbol. If method is non-nil, then we assume the symbol references a module that contains that method.

 
               # File rdoc/code_objects.rb, line 482
def find_symbol(symbol, method = nil)
  result = nil

  case symbol
  when /^::(.*)/ then
    result = toplevel.find_symbol($1)
  when /::/ then
    modules = symbol.split(/::/)

    unless modules.empty? then
      module_name = modules.shift
      result = find_module_named(module_name)

      if result then
        modules.each do |name|
          result = result.find_module_named(name)
          break unless result
        end
      end
    end

  else
    # if a method is specified, then we're definitely looking for
    # a module, otherwise it could be any symbol
    if method
      result = find_module_named(symbol)
    else
      result = find_local_symbol(symbol)
      if result.nil?
        if symbol =~ /^[A-Z]/
          result = parent
          while result && result.name != symbol
            result = result.parent
          end
        end
      end
    end
  end

  if result and method then
    fail unless result.respond_to? :find_local_symbol
    result = result.find_local_symbol(method)
  end

  result
end
            
initialize_classes_and_modules() click to toggle source
 
               # File rdoc/code_objects.rb, line 423
def initialize_classes_and_modules
  @classes     = {}
  @modules     = {}
end
            
initialize_methods_etc() click to toggle source
 
               # File rdoc/code_objects.rb, line 405
def initialize_methods_etc
  @method_list = []
  @attributes  = []
  @aliases     = []
  @requires    = []
  @includes    = []
  @constants   = []

  # This Hash maps a method name to a list of unmatched
  # aliases (aliases of a method not yet encountered).
  @unmatched_alias_lists = {}
end
            
methods_matching(methods, singleton = false) click to toggle source

Yields Method and Attr entries matching the list of names in methods. Attributes are only returned when singleton is false.

 
               # File rdoc/code_objects.rb, line 249
def methods_matching(methods, singleton = false)
  count = 0

  @method_list.each do |m|
    if methods.include? m.name and m.singleton == singleton then
      yield m
      count += 1
    end
  end

  return if count == methods.size || singleton

  # perhaps we need to look at attributes

  @attributes.each do |a|
    yield a if methods.include? a.name
  end
end
            
modules() click to toggle source

map the module hash to an array externally

 
               # File rdoc/code_objects.rb, line 218
def modules
  @modules.values
end
            
ongoing_visibility=(vis) click to toggle source

Change the default visibility for new methods

 
               # File rdoc/code_objects.rb, line 241
def ongoing_visibility=(vis)
  @visibility = vis
end
            
record_location(toplevel) click to toggle source

Record the file that we happen to find it in

 
               # File rdoc/code_objects.rb, line 281
def record_location(toplevel)
  @in_files << toplevel unless @in_files.include?(toplevel)
end
            
remove_classes_and_modules() click to toggle source

and remove classes and modules when we see a :nodoc: all

 
               # File rdoc/code_objects.rb, line 419
def remove_classes_and_modules
  initialize_classes_and_modules
end
            
remove_methods_etc() click to toggle source

If a class’s documentation is turned off after we’ve started collecting methods etc., we need to remove the ones we have

 
               # File rdoc/code_objects.rb, line 401
def remove_methods_etc
  initialize_methods_etc
end
            
set_current_section(title, comment) click to toggle source

Handle sections

 
               # File rdoc/code_objects.rb, line 539
def set_current_section(title, comment)
  @current_section = Section.new(title, comment)
  @sections << @current_section
end
            
set_visibility_for(methods, vis, singleton = false) click to toggle source

Given an array methods of method names, set the visibility of the corresponding AnyMethod object

 
               # File rdoc/code_objects.rb, line 272
def set_visibility_for(methods, vis, singleton = false)
  methods_matching methods, singleton do |m|
    m.visibility = vis
  end
end
            
toplevel() click to toggle source

Return the toplevel that owns us

 
               # File rdoc/code_objects.rb, line 466
def toplevel
  return @toplevel if defined? @toplevel
  @toplevel = self
  @toplevel = @toplevel.parent until TopLevel === @toplevel
  @toplevel
end
            

Protected Instance Methods

classes_hash() click to toggle source

return the classes Hash (only to be used internally)

 
               # File rdoc/code_objects.rb, line 225
def classes_hash
  @classes
end
            
modules_hash() click to toggle source

return the modules Hash (only to be used internally)

 
               # File rdoc/code_objects.rb, line 233
def modules_hash
  @modules
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus