Ruby Set subtract method

In ruby programming language, subtract() Set method are accept an enumerable object and this method are remove all set element which is exist in this enumerable object.

set.subtract(enumerable) -> self

After remove object this method is return self.

Example of subtract() Set method

# Example 1
require "set"

s = Set[2,9,6,4,8,5]

print(" Before subtract ") 
print("\n s : ",s.to_a)

r = s.subtract([4,9])

print("\n After subtract ") 
print("\n s : ",s.to_a)
print("\n r : ",r.to_a)
Ruby set subtract method example 1
 Before subtract 
 s : [2, 9, 6, 4, 8, 5]
 After subtract 
 s : [2, 6, 8, 5]
 r : [2, 6, 8, 5]


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved