Hi all,
I hope it's ok that I ask this question here, I don't wanted to
subscribe to two other lists. If I have more questions regarding ruby
itself I will do this.
I've seen the ||= operator several times in codes, screencasts and so
on, but I don't know it's use. Surely this will be no problem for
nearly every developer here, so thank you in advance.
= means “return what you have already. If you’re nil, then go get a value.”
This is called “menoinizing” and is a nice way to cache values.
Rails actually uses this a lot… when you have Post has_many :comments, the .comments method on an instance of a Post is created and does something similar: