Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Set#reset

() -> self
reset → self

Resets the internal state of self; returns self.

A set relies on the hash results of each element being consistent. Modifying an element in a way that changes the results of hash may allow duplicate elements in the set:

Example
array = [1]
set = Set[array]  # => Set[[1]]
array << 2
set.add(array)    # => Set[[1, 2], [1, 2]]

Calling reset will recalculate all of the hash values and remove duplicate elements:

Example
set.reset         # => Set[[1, 2]]
See also #replace #select! #reject! #size also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0