Ruby | clear() function
Last Updated :
06 May, 2019
The clear() function in Ruby is used to remove all the elements of the given array and returns the array with no elements.
Syntax: Array.clear
Here Array is the input array whose elements are to be cleared.
Parameters: This function does not accept any parameter.
Returns: the array with no elements.
Example 1:
Array1 = [ "Alphabets" , "a" , "b" , "c" , "d" , "e" ]
Array2 = [ "Names" , "gfg" , "Geeks" , "Geek" , "GeeksforGeeks" ]
Array3 = [ "City" , "Kolkata" , "Mumbai" , "Delhi" , "Patna" ]
A = Array1.clear
B = Array2.clear
C = Array3.clear
puts "#{A}"
puts "#{B}"
puts "#{C}"
|
Output:
[]
[]
[]
Example 2:
Array1 = []
Array2 = [ 1 , 2 ]
Array3 = [ "a" , "b" , "c" ]
puts "#{Array1.clear}"
puts "#{Array1.clear}"
puts "#{Array1.clear}"
|
Output:
[]
[]
[]
Reference: https://devdocs.io/ruby~2.5/array#method-i-clear
Share your thoughts in the comments
Please Login to comment...