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
set.c
View on GitHub ↗
static VALUE
set_i_join(int argc, VALUE *argv, VALUE set)
{
rb_check_arity(argc, 0, 1);
return rb_ary_join(set_i_to_a(set), argc == 0 ? Qnil : argv[0]);
}
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.