红宝石 |范围 new()函数
new()是 Ruby 中的一个内置方法,它返回一个新的数字范围。
Syntax: range1.new(first, last)
Parameters: The function accepts first and last which is the range that is to be created.
Return Value: It returns the range of numbers.
示例 1 :
# Ruby program for new()
# method in Range
# Initialize range
range1 = Range.new(8, 12)
# Prints the range
puts range1
输出:
8..12
示例 2 :
# Ruby program for new()
# method in Range
# Initialize range
range1 = Range.new(7, 9)
# Prints the range
puts range1
输出:
7..9