Statements
From Ruby Standard Wiki
Syntax
statement ::
expression-statement
| alias-statement
| undef-statement
| if-modifier-statement
| unless-modifier-statement
| while-modifier-statement
| until-modifier-statement
| rescue-modifier-statement
| rescue-modifier-statement
| assignment-statement
See §13.3.6 for alias-statement.
See §13.3.7 for undef-statement.
See §11.3.1 for assignment-statement.
Semantics
See §11.3.1 for assignment-statement.
Contents |
12.1 The expression statement
Syntax
expression-statement ::
expression
Semantics
An expression-statement is evaluated as follows:
- Evaluate the expression.
- The resulting value is the value of the expression-statement.
12.2 The if modifier statement
Syntax
if-modifier-statement ::
statement [no line-terminator here] if expression
The expression of an if-modifier-statement shall not be a jump-expression.
Semantics
An if-modifier-statement of the form S if E, where S is the statement and E is the expression, is evaluated as follows:
- Evaluate the if-expression of the form
ifEthenSend. - The resulting value is the value of the if-modifier-statement.
12.3 The unless modifier statement
Syntax
unless-modifier-statement ::
statement [ no line-terminator here ] unless expression
The expression of an unless-modifier-statement shall not be a jump-expression.
Semantics
An unless-modifier-statement of the form S unless E, where S is the statement and E is the expression, is evaluated as follows:
- Evaluate the unless-expression of the form
unlessEthenSend. - The resulting value is the value of the unless-modifier-statement.
12.4 The while modifier statement
Syntax
while-modifier-statement ::
statement [ no line-terminator here ] while expression
The expression of an while-modifier-statement shall not be a jump-expression.
Semantics
An while-modifier-statement of the form S while E, where S is the statement and E is the expression, is evaluated as follows:
- Evaluate the while-expression of the form
whileEdoSend. - The resulting value is the value of the while-modifier-statement.
12.5 The until modifier statement
Syntax
until-modifier-statement ::
statement [ no line-terminator here ] until expression
The expression of an until-modifier-statement shall not be a jump-expression.
Semantics
An until-modifier-statement of the form S until E, where S is the statement and E is the expression, is evaluated as follows:
- Evaluate the until-expression of the form
untilEdoSend. - The resulting value is the value of the until-modifier-statement.
12.6 The rescue modifier statement
Syntax
rescue-modifier-statement ::
main-statement-of-rescue-modifier-statement [ no line-terminator here ]
rescue fallback-statement-of-rescue-modifier-statement
main-statement-of-rescue-modifier-statement ::
statement
fallback-statement-of-rescue-modifier-statement ::
statement but not statement-not-allowed-in-fallback-statement
statements-not-allowed-in-fallback-statement ::
keyword-AND-expression
| keyword-OR-expression
| if-modifier-statement
| unless-modifier-statement
| while-modifier-statement
| until-modifier-statement
| rescue-modifier-statement
Semantics
A rescue-modifier-statement is evaluated as follows:
- Evaluate the main-statement-of-rescue-modifier-statement. Let V be the resulting value.
- If an instance of the class
StandardErroris raised and not handled in Step a, evaluate fallback-statement-of-rescue-modifier-statement. The resulting value is the value of the rescue-modifier-statement. - If no instances of the class
Exceptionare raised in Step a, or all the instances of the classExceptionraised in Step a are handled in Step a, the value of the rescue-modifier-statement is V.