Ruby | Numeric negative? function
Last Updated :
19 Mar, 2024
The negative?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is a negative one, else it returns false.
Syntax: num.negative?()
Parameters: The function needs a number which is to be checked for.
Return Value: It returns returns a boolean value.
Example 1:
# Ruby program for negative?()
# method in Numeric
# Initialize a number
num1 = -15
# Prints negative or not
puts num1.negative?()
|
Output:
true
Example 2:
# Ruby program for negative?()
# method in Numeric
# Initialize a number
num1 = 15
# Prints negative or not
puts num1.negative?()
|
Output:
false
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...