A set is an ordered collection of unique items that cannot be duplicated. The set A can be said to be a proper set of set B. This can happen if set A contains all the elements or items of set B but with at least one or more that is not in set B.
set1.proper_superset(set2)
set1: This is the set we want to check if it is a proper superset of another set, set2.
set2: This is the other set that we want to check with set set1.
The value returned is a Boolean value. If the set set1 is a proper superset of the set set2 , then a true is returned. Otherwise, it returns false.
# require the set classrequire "set"# create some setsEvenNumbers = Set.new([2, 4, 6, 8, 10])NumbersToTen = Set.new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])Names = Set.new(["Amaka", "Titi"])Workers = Set.new(["Amaka", "Chioma", "Titi"])EmptySet = Set.new([])Alphabets = Set.new(["a", "b", "c", "d", "e", "f", "g","h", "i", "j", "k", "l", "m", "n", "o", "p", "q","r", "s", "t", "u", "v", "w", "x", "y", "z"])Vowels = Set.new(["a", "e", "i", "o", "u"])# check if proper supersets existsputs NumbersToTen.proper_superset?(EvenNumbers) # trueputs Names.proper_superset?(Workers) # falseputs EmptySet.proper_superset?(Names) # falseputs Alphabets.proper_superset?(Vowels) # true
set class.EvenNumbers, NumbersToTen, Names, Workers, EmptySet, Alphabets, Vowels).proper_superset?() method and print the results to the console screen.