What’s the difference between these two Ruby if statements when we put a then at the end of the if statement?
if(val == "hi") then
something.meth("hello")
else
something.meth("right")
end
and
if(val == "hi")
something.meth("hello")
else
something.meth("right")
end
thenis a delimiter to help Ruby identify the condition and the true-part of the expression.ifconditionthentrue-partelsefalse-partendthenis optional unless you want to write anifexpression in one line. For an if-else-end spanning multiple lines the newline acts as a delimiter to split the conditional from the true-part