Guest User

Untitled

a guest
Jul 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. def hello
  2. puts "hello world"
  3. puts "hello hell"
  4. end
  5.  
  6. class Method
  7. SHOW_TRACE = false
  8. def trace_func event, file, line, id, binding, classname
  9. puts "%8s %s:%-2d %s %8s" % [event, file, line, id, classname] if SHOW_TRACE
  10. return unless event == 'call'
  11. set_trace_func nil
  12.  
  13. @file, @line = file, line
  14. raise :found
  15. end
  16.  
  17. def source_location
  18. if @file.nil?
  19. args =[*(1..(arity<-1 ? -arity-1 : arity ))]
  20.  
  21. set_trace_func method(:trace_func).to_proc
  22. # begin; call *args; rescue Exception=>e; puts e.to_s; puts e.backtrace; end
  23. call *args rescue nil
  24. set_trace_func nil
  25. @file = File.expand_path(@file) if @file && File.exist?(File.expand_path(@file))
  26. end
  27. return [@file, @line] if File.exist?(@file.to_s)
  28. end
  29. end
  30.  
  31. puts method(:hello).source_location.inspect
Add Comment
Please, Sign In to add comment