finds the file and line of executed code
1 2 module Kernel 3 def which(&block) 4 result = 'No ruby call has happen in the given block!' 5 found = false 6 set_trace_func lambda { |event, file, line, id, binding, classname| 7 return unless event == 'call' 8 result = "#{file}:#{line}: " unless found 9 found = true 10 } 11 yield 12 set_trace_func(nil) 13 result 14 end 15 end 16 17 # test 18 require 'yaml' 19 puts which { [].to_yaml }