instance method
Set#replace
(::_Each[A]) -> self
replace(enum) → self
set.c
View on GitHub ↗
static VALUE
set_i_replace(VALUE set, VALUE other)
{
rb_check_frozen(set);
if (rb_obj_is_kind_of(other, rb_cSet)) {
set_i_initialize_copy(set, other);
}
else {
if (set_iterating_p(set)) {
rb_raise(rb_eRuntimeError, "cannot replace set during iteration");
}
// make sure enum is enumerable before calling clear
enum_method_id(other);
set_table_clear(RSET_TABLE(set));
set_merge_enum_into(set, other);
}
return set;
}
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]