Ruby | Set delete? function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 returns self after deletion of the object from the set, and it returns nil if the object is not present. Example 1: CPP #Ruby program to illustrate the #delete ? method #requires the set require "set" s1 = Set[1, 2, 3] #deletes 2 and prints self puts s1.delete ? (2) #deletes 1 and prints self puts s1.delete ? (1) #deletes 4 and prints self puts s1.delete ? (4) Output: Set: {1, 3} Set: {3} Example 2: CPP #Ruby program to illustrate the #delete ? method #requires the set require "set" s1 = Set[4, 7, 13, "q"] #deletes 2 and prints self puts s1.delete ? (2) #deletes 1 and prints self puts s1.delete ? (1) #deletes 4 and prints self puts s1.delete ? (13) Output: Set: {4, 7, "q"} Reference: https://devdocs.io/ruby~2.5/set#method-i-delete-3F Comment More infoAdvertise with us Next Article Ruby | Set delete() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Set-class Similar Reads 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 | Set flatten!() function The flatten!() is an inbuilt method in Ruby replaces the receiver with the result in place. Returns nil if no modifications were made. Syntax: s1.flatten!() Parameters: The function does not takes any parameter. Return Value: It returns the receiver with the result in place, or else returns nil if n 1 min read Ruby | Set clear() function 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 #req 1 min read Ruby | Set difference() function The difference is an inbuilt method in Ruby that returns a new set built by duplicating the set, removing every element that appears in the given enumerable object. Syntax: s1.name - s2.name Parameters: The function does not takes any parameter. Return Value: It returns a new set built by duplicatin 1 min read Ruby | Set empty?() function The empty?() is an inbuilt method in Ruby returns true if the set is empty or it returns false. Syntax: s1.empty?() Parameters: The function does not takes any parameter. Return Value: It returns a boolean value. It returns true if the set is empty or it returns false. Example 1: Ruby # Ruby program 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 Like