Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Set#replace
replace(enum)
lib/set.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/set.rb, line 327
def replace(enum)
if enum.instance_of?(self.class)
@hash.replace(enum.instance_variable_get(:@hash))
self
else
do_with_enum(enum) # make sure enum is enumerable before calling clear
clear
merge(enum)
end
end
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}>