Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/display.rb
Instance Method Summary collapse
Instance Method Details
#display(*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 |
# File 'lib/display.rb', line 5 def display *args a = caller last_caller = a[0] if last_caller[1..1] == ":" # could 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 exact_line = File.readlines(file)[line.to_i - 1].strip parser=RedParse.new(exact_line) tree = parser.parse out = nil # the trick is to break out with the first method call... right_call_node = give_me_first_call_node tree # eureka out = "#{File.basename(file)},#{line}: " out += right_call_node.params.map{ |p| "#{p.unparse}=#{args.shift}" }.join(', ') puts out out end |
#give_me_first_call_node(tree) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/display.rb', line 33 def give_me_first_call_node tree tree.walk{|parent,i,subi,node| if node.class == RedParse::CallNode return tree else return give_me_first_call_node(node.right) end } end |