DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Finds The File And Line Of Executed Code
module Kernel
def which(&block)
result = 'No ruby call has happen in the given block!'
found = false
set_trace_func lambda { |event, file, line, id, binding, classname|
return unless event == 'call'
result = "#{file}:#{line}: " unless found
found = true
}
yield
set_trace_func(nil)
result
end
end
# test
require 'yaml'
puts which { [].to_yaml }





