Operators Are Methods

Operators are methods too.

We'll cover the following

As briefly mentioned earlier, a number has methods named like the arithmetic operators, +, -, *, and /.

It’s intuitive when considering that if everything is an object, then numbers are objects too. If doing things means operating with methods by way of calling them, then what would + be? A method.

If we call methods on objects using the dot (.) notation, then where are the dots in 2 + 3 * 4?

Ruby adds them for us. Take a look at the following code:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy