Module: Constree

Defined in:
lib/constree.rb,
lib/constree/node.rb,
lib/constree/version.rb

Defined Under Namespace

Classes: Node, NodeWithAncestors

Constant Summary collapse

VERSION =
"0.1.9"

Class Method Summary collapse

Class Method Details

.html_of(mod) ⇒ Object



33
34
35
# File 'lib/constree.rb', line 33

def html_of mod
  list(mod).first.tree_html_full
end

.list(node, seen = []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/constree.rb', line 16

def list node, seen=[]
  node = Node.new node unless node.is_a? Node
  seen << node if seen.empty?

  node.sub_nodes.each do |sub_n|
    seen << sub_n
    node.children_for_tree_graph << sub_n
    list(sub_n, seen) if sub_n.not_yet? seen
  end

  seen
end

.of(mod) ⇒ Object



29
30
31
# File 'lib/constree.rb', line 29

def of mod
  list(mod).first.tree_graph
end

.p(mod) ⇒ Object



37
38
39
# File 'lib/constree.rb', line 37

def p mod
  puts of mod
end

.uniq(mod, set = Set.new) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/constree.rb', line 7

def uniq(mod, set = Set.new)
  set << mod
  mod.constants.each do |name|
    sub_mod = mod.const_get(name)
    uniq(sub_mod, set) if ::Module === sub_mod && !set.include?(sub_mod)
  end
  set
end