Numbers and Expressions in Ruby

Numbers in Ruby:

There are two types of numbers in Ruby:

1. Integers: An integer is a sequence of digits, such as – 10, 100. In other words, numbers without decimal points are called Integers.

2. Floating-point numbers: Numbers with decimal points are usually called floats, such as – 2.5, and 5.5. The floating-point numbers are objects of the class Float.


1 + 2
"a" + "b" + "c"
100 - 5 * (2 - 1)
x + y

Expressions in Ruby:

When programming, an expression is a combination of data (such as numbers or strings of text), operators (such as + or -), and variables that, when understood by the computer, result in an answer of some form.

An expression is a chunk of Ruby code that the Ruby interpreter can evaluate to produce a value. primary expressions—such as literals, variable references, and method invocations—can be combined into larger expressions with operators, such as the assignment operator and the multiplication operator.