O'Reilly logo

Mastering Chef by Mayank Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic operations

Like all other programming languages, Ruby comes packed with a whole bunch of operators.

Arithmetic operators

Assume a = 2 and b = 4.

Operator

Description

Example

+

Addition: Adds values on either side of the operator

a + b will give 6

-

Subtraction: Subtracts the right-hand side operand from the left-hand side operand

a – b will give -2

*

Multiplication: Multiplies values on either side of the operator

a * b will give 8

/

Division: Divides the left-hand side operand by the right-hand side operand

b / a will give 2

%

Modulus: Divides the left-hand side operand by the right-hand side operand and returns the remainder

b % a will give 0

**

Exponent: Performs exponential (power) calculations on operators

a ** b will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required