Skip to content

Instantly share code, notes, and snippets.

View mediafinger's full-sized avatar
🏠
In Köln

Andreas Finger mediafinger

🏠
In Köln
View GitHub Profile
@mediafinger
mediafinger / trace_calls.rb
Last active August 29, 2015 14:26 — forked from toch/trace_calls.rb
Decorate any method in Ruby to get its call stack
def trace_calls_on
scope = {}
trace = TracePoint.new(:call, :line) do |tp|
case tp.event
when :call then puts "#{tp.path}:#{tp.lineno} #{tp.defined_class}::#{tp.method_id} " \
"called from #{scope[:path]}:#{scope[:lineno]} #{scope[:class]}::#{scope[:method_id]}"
when :line then scope = {
event: :line,
lineno: tp.lineno,
path: tp.path,