What is integer? in Ruby?

The num.integer? function in Ruby returns true if the number is an integer; otherwise, it returns false.

Figure 1 shows the visual representation of the num.integer? function.

Figure 1: Visual representation of the num.integer? function

Syntax

num.integer?
# where num is the number which is to be checked for integer

Return value

This function returns true if the number is an integer; otherwise, it returns false.

Example

#non-integer
print "(3.3).integer? : ",(3.3).integer? , "\n"
#integer
print "(4).integer? : ",(4).integer?, "\n"

Free Resources