2 ms·
Not sure I understand this example from Perl but Ruby has ||= that checks for nil but not defined. You can do a ||= b And if a is nil then it will get the va
by gls2ro 2y ago
Not sure I understand this example from Perl but Ruby has ||= that checks for nil but not defined.
You can do
a ||= b
And if a is nil then it will get the value from b else it will remain with the current value
- viraptor 2y agoThis really checks for true values, which is fine for nil and numbers. But it will fail you if you want to cache `false` or any falsey object.