📜  红宝石 |数值方法

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

红宝石 |数值方法

<=>是 Ruby 中的一个内置方法,如果两个数字相等则返回 0,否则返回 1。

示例 1

Ruby
# Ruby program for <=> method in Numeric
 
# Initialize two numbers
a = 19
b = 4
 
# Prints 0 if equal else 1
puts  a<=>b


Ruby
# Ruby program for <=> method in Numeric
 
# Initialize two numbers
a = 13
b = 13
 
# Prints 0 if equal else 1
puts  a <=> b


输出

1

示例 2

红宝石

# Ruby program for <=> method in Numeric
 
# Initialize two numbers
a = 13
b = 13
 
# Prints 0 if equal else 1
puts  a <=> b

输出

0