📜  红宝石 |理性==方法

📅  最后修改于: 2022-05-13 01:55:49.707000             🧑  作者: Mango

红宝石 |理性==方法

==是 Ruby 中的一个内置方法,如果两个有理数相同则返回布尔值 true,否则返回 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