Syntax and Expressions
Ruby is a case-sensitive language. Apart from within identifiers and some literals, blank space and comments may be placed anywhere as needed. Line breaks are treated as blank space only when used to clearly show a line is continuing; otherwise, they are treated as phrase delimiters.
Identifiers
Example:
An identifier in Ruby begins with an alphabetic character or underscore (_) and consists of alphanumeric characters or underscores (_). There is no limit on length.
Comments
Example:
Strings beginning with # are considered comments.
Reserved Words
The following are reserved words:
Reserved words cannot be used for names of classes, variables, or the like. However, words prefixed by $ or @ are not considered reserved. Furthermore, these words can be used as method names after def, after a method-call period, and in other cases where it is clear that the word is acting as a method name.
Expressions
Example
The term "expressions" encompasses everything from variables and literals to operational forms and control structures.
A collection of these expressions makes up a Ruby program. Expressions are separated from one another with semicolons (;) or line breaks. However, a line break following a backslash is not considered a new expression boundary; instead, the expression continues on the next line.
Expressions can be grouped with parentheses.
Last updated