在 IRB 中探索/调试。对方法进行猴子修补,然后“撤消”方法在不退出IRB的情况下进行这种改变?
我发现 IRB 作为试错式调试工具非常有用,我真的不知道问题从何而来,但可以利用 IRB 的 REPL 性质来快速迭代一系列潜在的重现方法一个问题并将其提炼出来。
有时,我决定重新打开属于已加载 gem 的类,并向方法添加一些调试输出,或者完全重写该方法。一旦完成,是否有一个简单的方法“un-monkey patch”类,而不退出IRB并重新启动它(我当前的方法)?
I find IRB extremely useful as a tool for trial and error style debugging, where I don't really know where a problem is coming from, but can take advantage of the REPL nature of IRB to quickly iterate through a list of potential ways to reproduce an issue and distill it down.
Occasionally I decide to re-open a class belonging to a loaded gem and add some debug output to a method, or override the method entirely. Once that is done, is there an easy to way "un-monkey patch" the class, without quitting IRB and restarting it (my current approach)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要重新定义方法,您可以为旧方法创建
别名
,然后定义新方法。完成后,您可以再次重新定义该方法并调用该方法别名。第一步:
完成后:
If you're redefining a method, you could create and
alias
for the old method and then define your new one. When you're done, you could redefine the method yet again and call the method alias.Step one:
When you're done: