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#replace

(::_Each[A]) -> self
replace(enumerable) → self

Replaces the contents self with the contents of the given enumerable; returns self:

Example
set = Set[1, 'c', :s] # => Set[1, "c", :s]
set.replace([1, 2])   # => Set[1, 2]

Related: see Methods for Assigning.

See also #reject! #reset #proper_superset? #select! also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0