The subtract() is an inbuilt method in Ruby returns the set after deleting all the objects that appear in the enum that is passed.
Syntax: s1_name.subtract(enum)
Parameters: The function takes an object enum whose elements are deleted from the set.
Return Value: It returns self object after removing all elements are removed of enum from set.
Example 1:
# Ruby program to illustrate # the subtract() method # requires the set require "set" s1 = Set[2, 12, 78, 10, 87, 98] s2 = Set[2, 10, 87] # subtract method used puts s1.subtract(s2) |
chevron_right
filter_none
Output:
Set: {12, 78, 98}
Example 2:
# Ruby program to illustrate # the subtract() method # requires the set require "set" s1 = Set[4, 5, 6, 7, 10] # subtract method used puts s1.subtract([5, 7]) |
chevron_right
filter_none
Output:
Set: {4, 6, 10}
Recommended Posts:
- Ruby | Set add? function
- Ruby | pop() function
- Ruby | at() function
- Ruby | Enumerable none?() function
- Ruby | Enumerable all? function
- Ruby | Enumerable one? function
- Ruby | Matrix lup() function
- Ruby | Set reset() function
- Ruby | Enumerable sum() function
- Ruby | Enumerator each function
- Ruby | Set replace() function
- Ruby | Enumerator::new function
- Ruby | Regexp eql?() function
- Ruby | Random hex() function
- Ruby | Rational quo() function
- Ruby Array () function with example
- Ruby | Enumerable min() function
- Ruby | StringScanner pos= function
- Ruby Integer abs() function with example
- Ruby | StringScanner pos function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

