Skip to main content

Ruby Set subset method

In ruby programming, subset() set method are use to check if the set is a subset of the given set. When the set is a subset of given set in then this method return true value otherwise return false value. Syntax of this method as follows.

set.subset(set) -> boolean true or false

This method are takes a parameter which is form of set.

Example of subset?() Set method

# Example 1
require "set"

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

# Check whether given set is subset of s.
r1 = Set[5,9].subset?(s)
r2 = Set[1,2,9].subset?(s)

print(" s  : ",s.to_a)
# Display result
print("\n r1 : ",r1)
print("\n r2 : ",r2)
Ruby set subset method example 1
 s  : [2, 9, 6, 4, 8, 5]
 r1 : true
 r2 : false


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