Re:Ruby Tips, Part 5
by matsadler on Tuesday April 22, 2014 @04:59PM
(#7630404)
Here's an example that shows x ||= y behaves like x || x = y, rather than x = x || y
This outputs:
and you can see that the output for ||= matches the output for x || x = y
[ Parent
| on HN ]
I didn't mean that it is "x = x || y", I meant "it's completely ad hoc".
For example, if you try "x || x = y" you will get an exception if x is not defined, but "x ||= y" will work fine. The same is true of constants "X || X = 1" will explode while "X ||= 1" will work fine.