A TopLevel context is a source file
# File rdoc/code_objects.rb, line 518
def TopLevel.all_classes_and_modules
@@all_classes.values + @@all_modules.values
end
# File rdoc/code_objects.rb, line 522
def TopLevel.find_class_named(name)
@@all_classes.each_value do |c|
res = c.find_class_named(name)
return res if res
end
nil
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 496
def add_class_or_module(collection, class_type, name, superclass)
cls = collection[name]
if cls
puts "Reusing class/module #{name}" if $DEBUG
else
if class_type == NormalModule
all = @@all_modules
else
all = @@all_classes
end
cls = all[name]
if !cls
cls = class_type.new(name, superclass)
all[name] = cls unless @done_documenting
end
puts "Adding class/module #{name} to #@name" if $DEBUG
collection[name] = cls unless @done_documenting
cls.parent = self
end
cls
end
# File rdoc/code_objects.rb, line 534
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 530
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.