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 self only. 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. 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} Set: {3} Example 2: CPP #Ruby program to illustrate the #delete method #requires the set require "set" s1 = Set[11, 12, 33, "a"] #deletes 'a' and prints self puts s1.delete("a") #deletes 11 and prints self puts s1.delete(11) #deletes 33 and prints self puts s1.delete(33) Output: Set: {11, 12, 33} Set: {12, 33} Set: {12} Reference: https://devdocs.io/ruby~2.5/set#method-i-delete Comment More infoAdvertise with us Next Article Ruby | Hash 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 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 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 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 | Hash delete() function delete() is an Hash class method which deletes the key-value pair and returns the value from hash whose key is equal to key. Syntax: Hash.delete() Parameter: Hash array Return: value from hash whose key is equal to deleted key. Example #1: Ruby # Ruby code for delete() method # declaring Hash value 1 min read Ruby | Hash delete_if() function delete_if() is a Hash class method which delete_if the key-value pair if the block condition is true Syntax: Hash.delete_if() Parameter: Hash array Block Condition Return: value from hash whose key is equal to delete_ifd key. Example #1: Ruby # Ruby code for delete_if() method # declaring Hash value 1 min read Like