红宝石 |范围结束()函数
end()是 Ruby 中的内置方法,返回给定范围的最后一个元素。
Syntax: range1.end()
Parameters: The function accepts no parameter
Return Value: It returns the last element of the given range.
示例 1 :
# Ruby program for end() method in Range
# Initialize range
range1 = (0..10)
# Prints the last element
puts range1.end()
输出:
10
示例 2 :
# Ruby program for end() method in Range
# Initialize range
range1 = (10..20)
# Prints the last element
puts range1.end()
输出:
20