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