Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def hello
- puts "hello world"
- puts "hello hell"
- end
- class Method
- SHOW_TRACE = false
- def trace_func event, file, line, id, binding, classname
- puts "%8s %s:%-2d %s %8s" % [event, file, line, id, classname] if SHOW_TRACE
- return unless event == 'call'
- set_trace_func nil
- @file, @line = file, line
- raise :found
- end
- def source_location
- if @file.nil?
- args =[*(1..(arity<-1 ? -arity-1 : arity ))]
- set_trace_func method(:trace_func).to_proc
- # begin; call *args; rescue Exception=>e; puts e.to_s; puts e.backtrace; end
- call *args rescue nil
- set_trace_func nil
- @file = File.expand_path(@file) if @file && File.exist?(File.expand_path(@file))
- end
- return [@file, @line] if File.exist?(@file.to_s)
- end
- end
- puts method(:hello).source_location.inspect
Add Comment
Please, Sign In to add comment