Ruby | Array clear() operation Last Updated : 08 Jan, 2020 Summarize Comments Improve Suggest changes Share 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 at() 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 Like