Skip to content
Related Articles

Related Articles

Ruby | Set subset? function
  • Last Updated : 07 Jan, 2020
GeeksforGeeks - Summer Carnival Banner

The subset?() is an inbuilt method in Ruby returns true if the set is a subset of the given set.

Syntax: s1_name.subset?(s2_name)

Parameters: The function takes a mandatory parameter with which it is ch

Return Value: It returns self.

Example 1:






# Ruby program to illustrate 
# the subset?() method 
   
# requires the set 
require "set"
   
s1 = Set[2, 12, 78, 10, 87, 98
s2 = Set[2, 10, 87]
   
# reset method used 
puts s2.subset?(s1)

Output:

true

Example 2:




# Ruby program to illustrate 
# the subset?() method 
   
# requires the set 
require "set"
   
s1 = Set[2, 12, 78, 10, 87, 98
s2 = Set[1, 2, 3]
   
# reset method used 
puts s2.subset?(s1)

Output:

false

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :