instance method
Set#<<
(A) -> self
<<(p1)
set.c
View on GitHub ↗
static VALUE
set_i_add(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();
}
}
else {
set_insert_wb(set, item, NULL);
}
return set;
}
Alias of #add
Adds the given object to the set and returns self. Use Set#merge to add many elements at once.
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) #=> Set[1, 2]