红宝石 |范围 eql?()函数
eql?()是 Ruby 中的一个内置方法,如果两个给定范围相等,则返回布尔值 true,否则返回 false。
Syntax: range1.eql?(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 program for eql?() method in Range
# Initialize range
range1 = (0..10)
range2 = (0..10)
# Prints the boolean value
puts range1.eql?(range2)
输出:
true
示例 2 :
# Ruby program for eql?() method in Range
# Initialize range
range1 = (10..20)
range2 = (0..10)
# Prints the boolean value
puts range1.eql?(range2)
输出:
false