Module: Wanderer

Defined in:
lib/wanderer.rb,
lib/wanderer/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.search(receiver, look_up_method) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/wanderer.rb', line 22

def self.search(receiver, look_up_method)
  visited = []
  ancestors = receiver.singleton_class.ancestors

  ancestors.each do |ancestor|
    visited << ancestor
    return visited if ancestor.instance_methods(false).include?(look_up_method.to_sym)
  end

  visited << "method_missing"

  ancestors.each do |ancestor|
    visited << ancestor
    return visited if ancestor.instance_methods(false).include? :method_missing
  end
end

.walk(receiver, look_up_method) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wanderer.rb', line 6

def self.walk(receiver, look_up_method)
  visited = search(receiver, look_up_method)

  g = GraphViz.new( :G, :type => :digraph )

  visited[0...-1].each_with_index do |item, index|
    a = g.add_nodes(item.to_s)
    b = g.add_nodes(visited[index+1].to_s)
    g.add_edges(a, b)
  end

  # Generate output image
  g.output( :png => "chain.png" )
  visited
end