January 2024
Intermediate to advanced
718 pages
20h 15m
English
Ruby has the basic set of operators (+, -, *, /, and so on) as well as a few surprises. A complete list of the operators, and their precedences, is given in Table 19, Ruby operators (high to low precedence).
In Ruby, many binary operators are implemented as method calls. For example, when you write a * b + c, you’re actually asking the object referenced by a to execute the method *, passing in the parameter b. You then ask the object that results from that calculation to execute the + method, passing c as a parameter. This is the same as writing the following (perfectly valid) Ruby:
| | a, b, c = 1, 2, 3 |
| | a * b + c # => 5 |
| | (a.*(b)).+(c) # => 5 |
Because everything is an object and because you can redefine instance ...
Read now
Unlock full access