A TopLevel context is a source file
# File rdoc/code_objects.rb, line 655
def self.all_classes_and_modules
@@all_classes.values + @@all_modules.values
end
# File rdoc/code_objects.rb, line 659
def self.find_class_named(name)
@@all_classes.each_value do |c|
res = c.find_class_named(name)
return res if res
end
nil
end
# File rdoc/code_objects.rb, line 667
def self.find_file_named(name)
@@all_files[name]
end
Adding a class or module to a TopLevel is special, as we only want one copy of a particular top-level class. For example, if both file A and file B implement class C, we only want one ClassModule object for C. This code arranges to share classes and modules between files.
# File rdoc/code_objects.rb, line 618
def add_class_or_module(collection, class_type, name, superclass)
cls = collection[name]
if cls then
cls.superclass = superclass unless cls.module?
puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC
else
if class_type == NormalModule then
all = @@all_modules
else
all = @@all_classes
end
cls = all[name]
if !cls then
cls = class_type.new name, superclass
all[name] = cls unless @done_documenting
else
# If the class has been encountered already, check that its
# superclass has been set (it may not have been, depending on
# the context in which it was encountered).
if class_type == NormalClass
if !cls.superclass then
cls.superclass = superclass
end
end
end
collection[name] = cls unless @done_documenting
cls.parent = self
end
cls
end
# File rdoc/code_objects.rb, line 604
def file_base_name
File.basename @file_absolute_name
end
# File rdoc/code_objects.rb, line 675
def find_class_or_module_named(symbol)
@@all_classes.each_value {|c| return c if c.name == symbol}
@@all_modules.each_value {|m| return m if m.name == symbol}
nil
end
# File rdoc/code_objects.rb, line 671
def find_local_symbol(symbol)
find_class_or_module_named(symbol) || super
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 see Improve the docs, or visit Documenting-ruby.org.