Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Set.[]
[X] (*X) -> ::Set[X]
Set[*objects] → new_set
set.c
View on GitHub ↗
static VALUE
set_s_create(int argc, VALUE *argv, VALUE klass)
{
VALUE set = set_alloc_with_size(klass, argc);
set_table *table = RSET_TABLE(set);
int i;
for (i=0; i < argc; i++) {
set_table_insert_wb(table, set, argv[i]);
}
return set;
}
Returns a new set populated with the given objects:
Example
Set[1, 'one', :one, 1.0, %w[a b c], {foo: 0, bar: 1}] # => Set[1, "one", :one, 1.0, ["a", "b", "c"], {foo: 0, bar: 1}] Set[Set[0, 1, 2], Set[%w[a b c]]] # => Set[Set[0, 1, 2], Set[["a", "b", "c"]]] Set[] # => Set[]
Related: see Methods for Creating a Set.