一个很好用的工具,那就是pry
gem install pry
然后再程序中加入binding.pry, 当系统执行到这里后,就会自行停下来。
2: attr_accessible :name, :content, :published_at
3: has_many :comments
4:
5: def word_count
6: words = content.scan(/\w+/)
=> 7: binding.pry
8: words.size
9: end
10: end然后就可以在对话框内输入任何参数, 比如输入words 就可以知道words的值
当然还有其他命令 比如 next, continue.
具体的请看源代码
https://github.com/nixme/pry-nav
本文介绍了如何使用pry工具进行代码调试,包括gem安装、使用binding.pry暂停执行及命令交互等功能。提供了实例代码帮助理解如何在代码中集成pry进行实时调试。
1960

被折叠的 条评论
为什么被折叠?



