The to_i
method of an integer instance returns the integer instance itself because it is already an integer.
integer.to_i
This method does not take any parameters.
The value returned is the integer integer
itself.
Let’s look at the code below:
# create some integersint1 = 23int2 = -10int3 = 1int4 = 30**100# invoke the to_i methodputs int1.to_iputs int2.to_iputs int3.to_iputs int4.to_i
int1
, int2
, int3
, and int4
.to_i
method on the integer instances and the returned values are printed to the system console.