A set is a data structure used to store elements or values that must be unique. In this shot, we will look at adding elements to a set in Ruby by using method
add() with the set instance.
element: This is the element we want to add to the set.
The value returned is a new set with the
element added to it.
requireto get the set class.
forloop to print the elements in the set we just created.
add()method of the set instance to add some elements to the set
Languagesthat we created.
forloop to print out the elements of the modified set.
View all Courses