I suspect he has something with a ruby ββparser. Because when writing a line, if
inline_if = 'value will not set but no error' if inline_if
The Ruby parser actually parses from left to right. Therefore, in the above line, he first encounters the setter method of the inline_if
variable. therefore, it actually defines this variable with the value nil
, and then checks the if inline_if
condition, which will evaluate to if nil
.
Now with the block if the condition
if block_if block_if = 'forget about setting value, I will raise an error' end
first tries to access the variable block_if
, which is not yet defined. therefore, this will result in an error.
Surprisingly, from the point of view of the programmer, both of the above blocks should be evaluated equally. but they behave differently
source share