使用 ||= 语法执行记忆有哪些缺点
我注意到有几个人评论了他们如何使用 ||=
来执行记忆化 很“草率”,但他们还是这么做了,“因为他们很匆忙”。
我还找到了 ActiveSupport::Memoizes。
我得出的结论是 ||=
有缺点。
那么它们是什么?
I have noticed several individuals comment on how their use of ||=
to perform memoization was 'sloppy' but they did it anyway 'because they were in a rush'.
I also found ActiveSupport::Memoizable.
I'm lead to conclude that ||=
has drawbacks.
So what are they?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,据我所知,最大的原因是你无法记住
nil
或false
这样的值。Well, the biggest reason I'm aware of is that you can't memoize
nil
orfalse
values like that.我建议阅读以下内容:
何时在 Ruby on Rails 中使用记忆化
这是:< br>
http://www.railway.at/articles /2008/09/20/记忆指南/
I suggest reading this:
When to use memoization in Ruby on Rails
And this:
http://www.railway.at/articles/2008/09/20/a-guide-to-memoization/