1. Logical operators
(1) Condition 1 | | Condition 2
Condition 1 is false , only need to judge condition 2
(2) Conditions 1 && conditions 2
Condition 1 is true , the condition must be judged 2
2. Range operator
(1) x.. Y from X to Y, including y
(2) X...y the previous element from X to Y, excluding Y
3. How to Handle exception
(1)
Begin
Handling of exceptions may occur
Rescue
Handling when an exception occurs
End
Specify variable name after rescue to get exception object
Such as:
Begin
Handling of exceptions may occur
Rescue = variable referencing an exception object
Handling when an exception occurs
End
Variable names are not specified, and variables that are automatically assigned when an exception occurs are used with the default variable name
Variable |
Significance |
$! |
The last exception that occurred (Exception object) |
[Email protected] |
Location information for the last occurrence of the exception |
(2) post-processing
Begin
Handling of exceptions may occur
Rescue = variable referencing an exception object
Handling when an exception occurs
Ensure
Processing that you want to perform regardless of whether an exception occurred
End
4. Rescue modifier
Expression 1-Rescue expression 2
An exception occurs in Expression 1, and the value of expression 2 becomes the value of the overall expression.
Equivalent notation:
Begin
Expression 1
Rescue
Expression 2
End
Ruby Knowledge Point three: operator