Ruby | Set subtract() function
Last Updated :
07 Jan, 2020
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:
require "set"
s1 = Set[ 2 , 12 , 78 , 10 , 87 , 98 ]
s2 = Set[ 2 , 10 , 87 ]
puts s1.subtract(s2)
|
Output:
Set: {12, 78, 98}
Example 2:
require "set"
s1 = Set[ 4 , 5 , 6 , 7 , 10 ]
puts s1.subtract([ 5 , 7 ])
|
Output:
Set: {4, 6, 10}
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...