Never been to DZone Snippets before?

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

About this user

Holger Kohnen holgerkohnen.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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 }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS