This is a personal memo.
About what if (x = test)
is doing. In ruby, assignment can be used in conditional expressions of variables.
if x = test
p x
end
=> nil
With if x = test
, the value of the variable test
is assigned to the variable x
.
If the variable test
from which it is assigned is false, the result will be false.
・ P x
"P" is the output. Meaning to output the variable x.
test = "test"
if x = test
p x
end
=> "test"
Recommended Posts