instance method
Set#add?
(A) -> self?
add?(obj) → self or nil
set.c
View on GitHub ↗
static VALUE
set_i_add_p(VALUE set, VALUE item)
{
rb_check_frozen(set);
if (set_iterating_p(set)) {
if (!set_table_lookup(RSET_TABLE(set), (st_data_t)item)) {
no_new_item();
}
return Qnil;
}
else {
return set_insert_wb(set, item, NULL) ? Qnil : set;
}
}
Adds the given object to the set and returns self. If the object is already in the set, returns nil.
Example
Set[1, 2].add?(3) #=> Set[1, 2, 3] Set[1, 2].add?([3, 4]) #=> Set[1, 2, [3, 4]] Set[1, 2].add?(2) #=> nil