红宝石 |有理负数?()函数
否定?()是 Ruby 中的一个内置函数,如果有理数小于零,则返回布尔值 true,否则返回 false。
Syntax: rat.negative?()
Parameters: The function accepts no parameter.
Return Value: It returns boolean value true if rational number is less than zero otherwise return false.
示例 1 :
# Ruby program for negative?() method
# Initialize rational number
rat1 = Rational(-2, 9)
# Prints the rational number
puts rat1.negative?()
输出:
true
示例 2 :
# Ruby program for negative?() method
# Initialize rational number
rat1 = Rational('1.23')
# Prints the rational number
puts rat1.negative?()
输出:
false