Class: RDoc::TopLevel

Inherits:
Object
  • Object
show all
Defined in:
lib/erbook/rdoc.rb

Class Method Summary collapse

Class Method Details

.all_classesObject

Returns an array of all classes recorded thus far.



16
17
18
# File 'lib/erbook/rdoc.rb', line 16

def self.all_classes
  @all_classes.values
end

.all_methodsObject

Returns an array of RDoc::AnyMethod objects representing all methods recorded thus far.



31
32
33
# File 'lib/erbook/rdoc.rb', line 31

def self.all_methods
  all_classes_and_modules.map {|c| c.method_list }.flatten
end

.all_modulesObject

Returns an array of all modules recorded thus far.



23
24
25
# File 'lib/erbook/rdoc.rb', line 23

def self.all_modules
  @all_modules.values
end

.parse(code_string, file_name = __FILE__) ⇒ Object

Returns a RDoc::TopLevel object containing information parsed from the given code string. This information is also added to the global TopLevel class state, so you can access it via the class methods of the TopLevel class.

If the file name (which signifies the origin of the given code) is given, it MUST have a “.c” or “.rb” file extension. Otherwise, RDoc will ignore the given code string! :-(



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/erbook/rdoc.rb', line 65

def self.parse code_string, file_name = __FILE__
  tl = TopLevel.new(file_name)
  op = DummyOptions.new
  st = Stats.new(0)

  result = Parser.for(tl, file_name, code_string, op, st).scan

  refresh_all_classes_and_modules

  result
end

.parse_file(file_name) ⇒ Object

Returns a RDoc::TopLevel object containing information parsed from the code in the given file. This information is also added to the global TopLevel class state, so you can access it via the class methods of the TopLevel class.

The given file name MUST have a “.c” or “.rb” file extension. Otherwise, RDoc will ignore the file! :-(



86
87
88
# File 'lib/erbook/rdoc.rb', line 86

def self.parse_file file_name
  parse File.read(file_name), file_name
end

.refresh_all_classes_and_modulesObject

Update the return value of the all_classes_and_modules() method to really include every class and every module seen thus far.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/erbook/rdoc.rb', line 39

def self.refresh_all_classes_and_modules
  visit = lambda do |node|
    if node.is_a? NormalClass or node.is_a? SingleClass
      @all_classes[node.full_name] = node

    elsif node.is_a? NormalModule
      @all_modules[node.full_name] = node
    end

    (node.classes + node.modules).each {|n| visit[n] }
  end

  all_classes_and_modules.each {|n| visit[n] }
end