Ruby | Array drop() operation Last Updated : 08 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#drop() : drop() is a Array class method which drops first 'n' elements from the array and returns the remaining elements. Syntax: Array.drop() Parameter: 'n' - no. of elements to drop. Return: array after removing first n elements Code #1 : Example for drop() method Ruby # Ruby code for drop() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, nil, nil, 50, 6] # drop puts "drop : #{a.drop(5)}\n\n" # drop puts "drop : #{b.drop(0)}\n\n" # drop puts "drop : #{c.drop(20)}\n\n" Output : drop : [6] drop : [1, 4, 1, 1, 88, 9] drop : [] Code #2 : Example for drop() method Ruby # Ruby code for drop() method # declaring array a = ["abc", "nil", "dog"] # declaring array b = ["cow", nil, "dog"] # declaring array c = ["cat", nil, nil] # drop puts "drop : #{a.drop(2)}\n\n" # drop puts "drop : #{b.drop(0)}\n\n" # drop puts "drop : #{c.drop(3)}\n\n" Output : drop : ["dog"] drop : ["cow", nil, "dog"] drop : [] Comment More infoAdvertise with us Next Article Ruby | Array map!() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Array-class Similar Reads Ruby | Array dig() operation Array#dig() : dig() is a Array class method which extracts the specific element out of the high dimension sequences. Syntax: Array.dig() Parameter: element position. Return: element from a specific location in sequence, returning nil if any intermediate step is nil. Code #1 : Example for dig() metho 1 min read Ruby | Array map!() operation Array#map!() : map!() is a Array class method which returns a new array containing the values returned by the block. Syntax: Array.map!() Parameter: Array Return: a new array containing the values returned by the block. Example #1 : Ruby # Ruby code for map!() method # declaring array a = [18, 22, 3 2 min read Ruby | Array at() operation Array#at() : at() is an Array class method which returns the element at the specific argumented index value. Syntax: Array.at() Parameter: - Arrays to search elements. - index to search Return: Array element at a specific index value Code #1 : Example for at() method Ruby # Ruby code for at() method 1 min read Ruby | Array compact() operation Array#compact () : compact () is a Array class method which returns the array after removing all the 'nil' value elements (if any) from the array. Syntax: Array.compact() Parameter: Array to remove the 'nil' value from. Return: removes all the nil values from the array. Code #1 : Example for compact 2 min read Ruby | Array compact!() operation Array#compact! () : compact! () is a Array class method which returns the array after removing all the 'nil' value elements (if any) from the array. If there are no nil values in the array it returns back the nil value. Syntax: Array.compact!() Parameter: Array to remove the 'nil' value from. Return 2 min read Ruby | Array clear() operation Array#clear() : clear() is an Array class method which removes all the array elements from it. Syntax: Array.clear() Parameter: Arrays to clear off Return: array with all elements cleared Code #1 : Example for clear() method Ruby # Ruby code for clear() method # declaring array a = [1, 2, 3, 4] # de 1 min read Like