A set is a data structure containing unique elements. The size of a set is the number of elements that are added to the set. It returns an integer representing the count of elements present in the set.
To get this size, we can use the size method.
Set.size
None.
An integer is returned. This integer represents the number of elements present in the set.
# require the set Class to use itrequire "set"# create setsLanguages = Set.new(["Ruby", "PHP","JavaScript","Python"])Numbers = Set.newNumbers << 1Numbers << 2Numbers << 3Techgiants = Set.new(["Google"])Techgiants.add("Netflix")Techgiants.add("Apple")Techgiants.add("Amazon")Techgiants.add("Meta")Emptyset = Set.new# print sizeputs Languages.sizeputs Numbers.sizeputs Techgiants.sizeputs Emptyset.size
set class.size method. We then print the results to the console.