红宝石 |有理分母()函数
denominator()是 Ruby 中的一个内置函数,它返回始终为正的分母。
Syntax: rat.denominator()
Parameters: The function accepts no parameter
Return Value: It returns the denominator which is always positive.
示例 1 :
# Ruby program for denominator() method
# Initialize rational number
rat1 = Rational(7, -3)
# Prints the rational number
puts rat1.denominator()
输出:
3
示例 2 :
# Ruby program for denominator() method
# Initialize rational number
rat1 = Rational(7)
# Prints the rational number
puts rat1.denominator()
输出:
1