Ruby drop array method
In ruby programming language, drop() method of array are use to drop initial n elements at beginning of array and get the remaining elements. This method takes a parameter-positive integer that represents the number of drop elements in front of the array. Its syntax is as follows.
|Parameter||Positive integer value|
|Return||Returns the remaining elements of array|
Ruby drop method example
See some examples for using the drop () method in this section. Which describes the working process of this method.
# Example 1 # Our array record = [4,5,6,7,8,9,10] # Drop 4 element data = record.drop(4) # Display array elements print(" record : ",record) print("\n data : ",data)
record : [4, 5, 6, 7, 8, 9, 10] data : [8, 9, 10]
In case drop() method parameter value is greater than length of array. Then this method returning an empty array.
# Example 2 # Our array record = [1,2,3,4,5] # Drop 4 element a = record.drop(4) # n more than array b = record.drop(6) # Display array elements print(" record : ",record) print("\n a : ",a) print("\n b : ",b)
record : [1, 2, 3, 4, 5] a :  b :