红宝石 |可枚举的 drop()函数
enumerable的drop()是 Ruby 中的一个内置方法,在删除前 N 个元素后返回枚举器中的其余元素。
Syntax: block.drop(N)
Parameters: The function takes N which signifies the number of elements to be dropped.
Return Value: It returns the rest elements after dropping first N elements.
示例 1 :
# Ruby program for drop method in Enumerable
# Initialize
enu = (1..50)
# returns rest elements
enu.drop(45)
输出:
[46, 47, 48, 49, 50]
示例 2 :
# Ruby program for drop method in Enumerable
# Initialize
enu = [1, 2, 3]
# returns rest elements
enu.drop(1)
输出:
[2, 3]