Skip to content

Instantly share code, notes, and snippets.

@mohitmun
Last active May 22, 2019 12:22
Show Gist options
  • Save mohitmun/dd1f4bffde8b23192433df1c93685b2e to your computer and use it in GitHub Desktop.
Save mohitmun/dd1f4bffde8b23192433df1c93685b2e to your computer and use it in GitHub Desktop.
#GistID: dd1f4bffde8b23192433df1c93685b2e
require 'pry'
class Test
def first_call(f)
a = f
b = 2
res = second_call(a,b)
puts "\n\n=== result res:#{res} ===\n\n"
return res
end
def second_call(aay, bbee)
return aay * bbee
end
end
trace = TracePoint.new(:call, :return) do |tp|
p ["#{tp.event} #{tp.defined_class}##{tp.method_id}:#{tp.lineno}", tp.self.method(tp.method_id).parameters.inspect, tp.binding.local_variables.map{|a| [a, tp.binding.local_variable_get(a)]} , tp.event == :return ? tp.return_value : "nop"]
#binding.pry
end
trace.enable
t = Test.new
v = t.first_call(ARGV[0])
puts "final #{v}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment