What is num.odd? in Ruby?

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

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

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

Syntax

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

Parameter

This function does not require a parameter.

Return value

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

Example

#odd number
print "(3).odd? : ",(3).odd? , "\n"
#even number
print "(4).odd? : ", (4).odd?, "\n"

Free Resources