Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Set#replace

replace(enum)

Replaces the contents of the set with the contents of the given enumerable object and returns self.

Example
set = Set[1, 'c', :s]             #=> #<Set: {1, "c", :s}>
set.replace([1, 2])               #=> #<Set: {1, 2}>
set                               #=> #<Set: {1, 2}>
See also #reject! #reset #proper_superset? #select! also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0