The following multi-line conditional statement returns unexpected result.
if (false and
false and
false
true)
puts 123
end
# => 123
Notice the missing condition. Wondering why ruby interpreter did not detect the syntax problem in the condition.
The newline character started a new expression, exactly the same way semicolon (;
) does it.
(false and false and false; true)
# => true
This operator is like the comma operator found in C and C++.
a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value
...and similar to a do
-form in Clojure:
Evaluates the expressions in order and returns the value of the last.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With