Integers in Ruby

Integer class is a built-in Ruby object instances of which (integers) are used to denote whole numbers e.g. -128, -64, 0, 1, 42, 43, 100.

Integers have many built-in methods. Some of the methods allow for basic arithmetic.

1 + 2  # Addition of 2 to 1. Gives 3.
1 - 2  # Subtraction of 2 from 1. Gives -1.
2 * 3  # Multiplication of 2 by 3. Gives 6.
10 / 2 # Division of 10 by 2. Gives 5.
2 ** 3 # Exponentiation of 2 to the power of 3. Gives 8.# 
10 % 6 # Remainder of division of 10 by 6 (modulo). Gives 4.

We use cookies and similar technologies to enhance the quality of services, maintain statistics and adjust marketing content. You will find more information in the Cookies Policy.

By clicking OK you grant consent to processing of your personal data by us and our Trusted Partners with the purpose of maintain statistics and adjustment of the marketing content pursuant to the Privacy Policy. If you wish to not grant that consent and/or limit its extent click Settings.