January 2024
Intermediate to advanced
718 pages
20h 15m
English
Ruby is a line-oriented language. Ruby expressions and statements are terminated at the end of a line unless the parser can determine that the statement is incomplete. Some examples are when the last token on a line is an operator or comma, or when an open delimiter, such as a parenthesis, square bracket, or curly brace has not been closed. A backslash at the end of a line also tells Ruby to continue the expression onto the next line:
| | # no backslash '\' needed -- ends with an operator |
| | d = 4 + 5 + |
| | 6 + 7 |
| | |
| | # no backslash '\' needed -- has an unclosed parenthesis |
| | e = (4 + 5 |
| | + 6 + 7) |
| | |
| | # backslash '\' needed -- ends with a number |
| | f = 8 + 9 \ |
| | + 10 |
A semicolon can be used to separate multiple expressions on a line: ...
Read now
Unlock full access