红宝石 |负数?函数
负数?()是 Ruby 中的一个内置方法,返回一个布尔值。如果数字为负数,则返回 true,否则返回 false。
Syntax: num.negative?()
Parameters: The function needs a number which is to be checked for.
Return Value: It returns returns a boolean value.
示例 1 :
# Ruby program for negative?()
# method in Numeric
# Initialize a number
num1 = -15
# Prints negative or not
puts num1.negative?()
输出:
true
示例 2 :
# Ruby program for negative?()
# method in Numeric
# Initialize a number
num1 = 15
# Prints negative or not
puts num1.negative?()
输出:
false