shou2017.com
JP

Operators in Ruby That Cannot Be Overridden (Redefined)

Sat Feb 17, 2018
Sat Aug 10, 2024

This is a note to deepen understanding and review for the Ruby certification exam.

List of Operators (Control Structures) That Cannot Be Overridden (Redefined) and Those That Can

+@ and -@ are unary operators representing expressions like +50 or -36.

Compound assignment operators, which are combinations of operators, cannot be redefined. For example, += cannot be overridden.

Control structures describe the structure of a program as “executing in order,” “executing repeatedly,” or “executing based on conditions.” These are referred to as control structures.

| Cannot Override | Can Override |
|:-----:|:-----:|
| =     |  \|   |
| ?:    | ^   |
| ..    | &   |  
| ...   | <=> |
| not   | ==  |   
| &&    | ===  |
| and   | =~ |
| \|\|  | > |
| or    | >=   |   
| ::    | <   |
|       | <=    |
|       | <<   |  
|       | >> |
|       | +  |
|       | -   |
|       | * |
|       | / |
|       | %    |  
|       | **  |
|       | ~   |
|       | +@   |  
|       | -@  |
|       | []  |  
|       | []=  |
|       | ` |
|       | ! |
|       | !=   |  
|       | !~  |

Operators and Their Precedence

+@ and -@ are unary operators representing expressions like +50 or -36.

| Precedence | Operator |
|:-----:|:-----:|
| High | ::  |   
|    | []   |
|    | !  ~  +@     |   
|    | **     |  
|    | -@     |   
|    | *  /  %      |  
|    | +  -     |
|    | <<  >>     |
|    | &     |
|    | \|  ^     |
|    | >  >=  <  <=     |
|    | <=>  ==  ===  !=  =~  !~     |
|    | &&     |
|    | \|\|     |
|    | ..  ...     |
|    | ?:     |
|    | =      |
|    | not    |
|  Low  | and or     |
See Also