Ruby | Array clear() operation Last Updated : 08 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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] # declaring array b = [111.11, 2.5, 4.3, 2.224] # clearing the arrays puts "clear a : #{a.clear()}\n\n" puts "clear b : #{b.clear()}\n\n" Output : clear a : [] clear b : [] Code #2 : Example for clear() method Ruby # Ruby code for clear() method # declaring array a = ["abc", "xyz", "dog"] # declaring array b = ["cow", "cat", "dog"] # declaring array c = ["cat", "1", "dog"] # clearing the array puts "clear a : #{a.clear()}\n\n" puts "clear b : #{b.clear()}\n\n" puts "clear c : #{c.clear()}\n\n" Output : clear a : [] clear b : [] clear c : [] Comment More infoAdvertise with us Next Article Ruby | Array clear() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Array-class Similar Reads Ruby | Array cycle() operation Array#cycle() : cycle() is a Array class method which returns the array by calling the given block each time for every element in the array 'n' no. of times and if 'nil' is given, then it will call it for forever. Syntax: Array.cycle() Parameter: block - condition n - number of times to call the blo 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 collect!() operation Array#collect!() : collect!() is an Array class method which invokes the argument block once for each element of the array, replacing the element with the value returned by the block Syntax: Array.collect!() Parameter: Arrays in which we want elements to be invoked Return: array with all the envoked 1 min read Ruby | Array collect() operation Array#collect() : collect() is an Array class method which invokes the argument block once for each element of the array. A new array is returned which has the value returned by the block. Syntax: Array.collect() Parameter: Arrays in which we want elements to be invoked Return: array with all the en 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 class each() operation Array#each() : each() is a Array class method which returns the array by following the condition in the given block once for each element in self. Syntax: Array.each() Parameter: block - condition to follow Return: Each array element following the condition Code #1 : Example for each() method Ruby # 1 min read Ruby | Array delete() operation Array#delete() : delete() is a Array class method which returns the array after deleting the mentioned elements. It can also delete a particular element in the array. Syntax: Array.delete() Parameter: obj - specific element to delete Return: last deleted values from the array. Code #1 : Example for 2 min read Ruby | Array drop() operation 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() 1 min read Ruby | Array class eql?() operation Array#eql?() : eql?() is a Array class method which checks if the two arrays are equal or not. Syntax: Array.eql?() Parameter: Arrays to compare Return: true - if the arrays are equal; otherwise false Code #1 : Example for eql?() method Ruby # Ruby code for eql?() method # declaring array a = [18, 2 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 Like