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