Class: Object

Inherits:
BasicObject
Defined in:
lib/show.rb

Instance Method Summary collapse

Instance Method Details

#give_me_first_call_node(tree) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/show.rb', line 40

def give_me_first_call_node tree
  tree.walk{|parent,i,subi,node|
    if node.class == RedParse::CallNode
     # eureka
      return tree
    else
      return give_me_first_call_node(node.right)
    end
  }
end

#show(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/show.rb', line 5

def show *args
 a = caller
 last_caller = a[0] 
 if last_caller[1..1] == ":"
   # might be like E:/dev/ruby/sane/spec/../lib/sane/require_relative.rb:9:in `require_relative'
   drive, file, line, *rest = last_caller.split(":")
 else
   # or like
   # "spec.analyze:9"
   file, line, *rest = last_caller.split(":")
 end
 
 if(file.include?('eval')) 
   out = '[eval] '
   names = args.map{|a| '?'}
 else 
   exact_line = File.readlines(file)[line.to_i - 1].strip
   parser = RedParse.new(exact_line)
   tree = parser.parse
   # the trick is to break out with the first method call...
   right_call_node = give_me_first_call_node tree
   names = right_call_node.params.map{|p| p.unparse}
   out = "[#{File.basename(file)},#{line}] "
 end
 
 
 args2 = names.map{ |n|
    "#{n}=#{args.shift.inspect}"
 }.join(', ')
 
 out += args2   
 puts out
 out
end