Skip to content

Instantly share code, notes, and snippets.

@cpetschnig
Created November 16, 2010 15:51
Show Gist options
  • Save cpetschnig/701959 to your computer and use it in GitHub Desktop.
Save cpetschnig/701959 to your computer and use it in GitHub Desktop.
Custom runtime evaluation/profiling
class Array
@@caller_counter = {}
def include_with_caller?(value)
key = caller[0,4].join('|')
@@caller_counter[key] = (@@caller_counter[key] || 0) + 1
include_without_caller?(value)
end
alias_method_chain :include?, :caller
def self.callers
@@caller_counter
end
def self.print_callers
@@caller_counter.map do |key, value|
trace = key.split('|')
%{\n#{trace.first.ljust(150)} #{value}\n#{trace[1..-1].join("\n")}}
end.join("\n--") + "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment