code debugging using global variables
Imagine that you want to have a breakpoint at a specific place, but this method is executed many times, or you want to have better control when execution should be stopped. Could be useful when you debug specs or methods which are executed multiple times.
You can use this approach:
# logic def method_1 ...code... binding.pry if $x ...code... end # place where you set this flag, could be inside spec def method_2 ...code... $x = true if rule? ...code... end
puts callerto display the current call stack. Could be useful if you need to understand from some method is called.
wtf(to see the last exception)