如何为 Ruby 编写猴子补丁?
我正在使用 Rails 3 并收到如下所示的错误:
undefined method `persisted?' for []:Array
我想使用 Monkeypatch 来修复此问题。首先:它应该是什么样子?我对Ruby源代码中Array类的嵌套知之甚少。我很感激指导。
I am using Rails 3 and getting an error that looks like this:
undefined method `persisted?' for []:Array
I want to monkeypatch to fix this problem. First of all: what is it supposed to look like? I know very little about the nesting of the Array class in Ruby's source code. I'd appreciate the guidance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您只需像编写任何其他类一样编写类和函数,然后将其添加到原始类定义中。
像这样:
basically you just write the class and function like you would for any other class and it gets added to the original class definition.
Like So:
猴子修补看起来像这样:
现在:询问 Array 实例是否持久化可能意味着什么?
Monkey-patching looks like this:
Now: what can you possibly mean by asking an Array instance whether it is persisted?