Ruby | Numeric nonzero? function
Last Updated :
19 Mar, 2024
The nonzero?() is an inbuilt method in Ruby returns self if the number is non-zero, else it returns nil.
Syntax: num.nonzero?()
Parameters: The function needs a number which is to be checked.
Return Value: It returns self or nil.
Example 1:
num1 = 12
puts num1.nonzero?()
|
Output:
12
Example 2:
num1 = 0
puts num1.nonzero?()
|
Output:
Share your thoughts in the comments
Please Login to comment...