红宝石 |范围 == 方法
==是 Ruby 中的一个内置方法,如果两个给定范围相等,则返回布尔值 true,否则返回 false。
Syntax: range1 == range2
Parameters: The function accepts no parameter
Return Value: It returns boolean value true if both the given ranges are equal, else it returns false.
示例 1 :
Ruby
# Ruby program for == method in Range
# Initialize range
range1 = (0..10)
range2 = (0..10)
# Prints the boolean value
puts range1 == range2
Ruby
# Ruby program for == method in Range
# Initialize range
range1 = (10..20)
range2 = (0..10)
# Prints the boolean value
puts range1 == range2
输出:
true
示例 2 :
红宝石
# Ruby program for == method in Range
# Initialize range
range1 = (10..20)
range2 = (0..10)
# Prints the boolean value
puts range1 == range2
输出:
false