Last active
May 22, 2019 12:22
-
-
Save mohitmun/dd1f4bffde8b23192433df1c93685b2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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