What is num.zero? in Ruby?

The num.zero? function returns true if the number is zero, and false otherwise.

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

Syntax

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

Parameter

This function does not require a parameter.

Return value

This function returns true if the number is zero. Otherwise, it returns false.

Code

#zero number
print "(0).zero? : ",(0).zero? , "\n"
print "(0.0).zero? : ",(0.0).zero? , "\n"
#non-zero number
print "(4).zero? : ", (4).zero?, "\n"
print "(4.5).zero? : ", (4.5).zero?, "\n"

Free Resources