I have noticed several individuals comment on how their use of ||=
to perform memoization was 'sloppy' but they did it anyway 'because they w开发者_JAVA技巧ere in a rush'.
I also found ActiveSupport::Memoizable.
I'm lead to conclude that ||=
has drawbacks.
So what are they?
Well, the biggest reason I'm aware of is that you can't memoize nil
or false
values like that.
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/
精彩评论