Skip to content

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

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.

See also .new #& also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0