Ruby | Set clear() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The clear() is an inbuilt method in Ruby which clears all the elements in the set. Syntax: s1.name.clear() Parameters: The function does not takes any parameter. Return Value: It returns self after clearing all the elements in the set. Example 1: CPP #Ruby program to illustrate the clear method #requires the set require "set" s1 = Set[2, 1] #Prints s1 puts s1 #Clears the set and returns self #which is printed puts s1.clear Output: Set: {2, 1} Set: {} Example 2: CPP #Ruby program to illustrate the clear method #requires the set require "set" s1 = Set[] #Prints s1 puts s1 #Add 10 to it s1 << 10 puts s1 #Clears the set and returns self #which is printed puts s1.clear Output: Set: {} Set: {10} Set: {} Reference: https://devdocs.io/ruby~2.5/set#method-i-clear Comment More infoAdvertise with us Next Article Ruby | Set clear() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Set-class Similar Reads Ruby | clear() function 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. 1 min read Ruby | Set add? function The add? is an inbuilt method in Ruby which adds the given object to the set and returns self. If the object is already in the set, returns nil. Syntax: s1.name.add?(object) Parameters: The function takes the object to be added to the set. Return Value: It returns self if the object is not in the se 1 min read Ruby | Set delete? function The delete?() is an inbuilt method in Ruby which deletes the given object from the set and returns the self object. In case the object is not present, it returns nil. Syntax: s1.name.delete(object) Parameters: The function takes a mandatory parameter object which is to be deleted. Return Value: It r 1 min read Ruby | Set delete() function The delete() is an inbuilt method in Ruby which deletes the given object from the set and returns the self object. In case the object is not present, it returns self only. Syntax: s1.name.delete(object) Parameters: The function takes a mandatory parameter object which is to be deleted. Return Value: 1 min read Ruby | SizedQueue clear() function The clear() is an inbuilt function in Ruby clears the SizedQueue. We can re-insert objects again to it till the declared size of the SizedQueue. Syntax: q_name.clear() Parameters: The function does not takes any element. Return Value: It clears the SizedQueue and does not returns anything. Example 1 1 min read Like