用 Pry 來 debug

  1. $ gem install pry
  2. Put require 'pry' at the top of your application file.
  3. Put binding.pry at where you want the execution to stop, but usually you want to put binding.pry right before where an exception(an error) happened. In short, you run into an error and then add binding.pry.
  4. binding.pry allows you to see the state of your app, and you can do some tests in it, such as changing the value of variables in binding.pry.
  5. Ctrl-D continues the execution.
  • 可以放不只一個 binding.pry 方便一次測試好幾個地方。
  • Debug 需要經驗,我目前經驗還不過,之後再補充。