Almann G. wrote:
The first and last statements make sense to me, but why is the second one
I find semantics like this troubling, and no documentation sheds light as
to what would cause this behavior.
I understand your concern. Let me try to clarify.
Expressions in Ruby can be like standalone statements. Statements are
terminated with an optional semicolon or with a newline. If a statement
is incomplete, it is understood to go on to the next line; if it is
complete, it is just as if terminated with a semicolon.
a = (4
is the same as
a = (4;
a = (4; +5)
That is, it evaluates a “4” and then evaluates a “+5” (which then is the
resultant value, as it was the last evaluated).
a = (4+
the parser is able to see that the expression is not complete, and is
apparently continued on the next line.