struct Set(T)
- Set(T)
- Struct
- Value
- Object
Overview
Set
implements a collection of unordered values with no duplicates.
An Enumerable
object can be converted to Set
using the #to_set
method.
Set
uses Hash
as storage, so you must note the following points:
- Equality of elements is determined according to
Object#==
andObject#hash
. 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.
Example
s1 = Set{1, 2}
s2 = [1, 2].to_set
s3 = Set.new [1, 2]
s1 == s2 # => true
s1 == s3 # => true
s1.add(2)
s1.concat([6, 8])
s1.subset_of? s2 # => false
s2.subset_of? s1 # => true
Included Modules
- Enumerable(T)
- Iterable(T)