3 ms·
that's along the lines of using or for nil returns. value = function_that_nils || "default" I've found it makes code more succinct.
by iamwil 18y ago
that's along the lines of using or for nil returns.
value = function_that_nils || "default"
I've found it makes code more succinct.
- old-gregg 18y agoCareful here: I've seen plenty of "Rubiomatic" bugs that look like this: value = function_that_nils or "default" ... which results in nil assignment to value. Accidental confusion between || and 'or' is very common in Ruby world IMO, almost like famous == vs = in C.
- iamwil 18y agoAgreed. I think one is for statements (or) and the other one is for expressions (||), so they have different operational precedence, even though you could use them interchangeably, as long as you knew what got executed first.