Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Set#join

(?::string separator) -> ::String
join(separator = $,) → string

Returns the string formed by joining the string-converted elements of self with the given separator (defaults to $,):

Example
$, # => nil
Set[*%w[foo bar baz]].join
# => "foobarbaz"
Set[*%w[foo bar baz]].join(', ')
# => "foo, bar, baz"

Flattens nested arrays:

Example
Set[[:foo, [:bar, [:baz, :bat]]]].join
# => "foobarbazbat"

Does not flatten nested sets:

Example
Set[Set[:foo, Set[:bar, Set[:baz, :bat]]]].join
# => "Set[:foo, Set[:bar, Set[:baz, :bat]]]"

Related: see Methods for Converting.

See also #intersection #keep_if #intersect? #length also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0