class Set - Documentation for Ruby 4.1
30-Dec-2025 736
The Set class implements a collection of unordered values with no duplicates. It is a hybrid of Array’s intuitive inter-operation facilities and Hash’s fast lookup.
Set is easy to use with Enumerable objects (implementing each). Most of the initializer methods and binary operators accept generic Enumerable objects besides sets and arrays. An Enumerable object can be converted to Set using the to_set method.
Set uses a data structure similar to Hash for storage, except that it only has keys and no values.
Equality of elements is determined according to Object#eql? and Object#hash. Use Set#compare_by_identity to make a set compare its elements by their identity.
Set assumes that the identity of each element does not change while it is stored. Modifying an element of a set will render the set to an unreliable state.
When a string is to be stored, a frozen copy of the string is stored instead unless the original string is already frozen.
class Set - Documentation for Ruby 4.1 #ruby #rubydeveloper #rubyonrails #class #Documentation #class https://rubyonrails.ba/link/class-set-documentation-for-ruby-4-1