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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
06 Jan, 2020
Like Article
Save Article