红宝石 |理性==方法
==是 Ruby 中的一个内置方法,如果两个有理数相同则返回布尔值 true,否则返回 false
Syntax: rat1 == rat2
Parameters: The function accepts no parameter
Return Value: It returns boolean value true if two rational numbers are same otherwise false
示例 1 :
Ruby
# Ruby program for == method
# Initialize rational number
rat1 = Rational(1, 3)
rat2 = Rational(1, 3)
# Prints the rational number
puts rat1 == rat2
Ruby
# Ruby program for == method
# Initialize rational number
rat1 = Rational('1/3')
# Prints the rational number
puts rat1 == 0.33
输出:
true
示例 2 :
红宝石
# Ruby program for == method
# Initialize rational number
rat1 = Rational('1/3')
# Prints the rational number
puts rat1 == 0.33
输出:
false