What is short circuit evaluation??
It means in a conditional statement with two conditions the second condition is evaluated only when the first condition is not enough to determine the value of expressionConsider a conditional statement
echo "Hello" if a && b. In && condition if the first condition is
false(considering a is defined as
false) then the result of
a && bis always
false. So in this ruby won't try to evaluate b.
In the above image when a is
falseit neither print
"Hello"nor raise any error. Means b is not evaluated.
But when the a is
true, a is not enough to determine the condition so the ruby will try to evaluate b. But since b is not defined the ruby will raise error saying
undefined local variable or method b