Skip to content
instance method

Array#join

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

Returns the new string formed by joining the converted elements of self; for each element element:

  • Converts recursively using element.join(separator) if element is a kind_of?(Array).

  • Otherwise, converts using element.to_s.

With no argument given, joins using the output field separator, $,:

Example
a = [:foo, 'bar', 2]
$, # => nil
a.join # => "foobar2"

With string argument separator given, joins using that separator:

Example
a = [:foo, 'bar', 2]
a.join("\n") # => "foo\nbar\n2"

Joins recursively for nested arrays:

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

Related: see Methods for Converting.

See also #intersection #keep_if #intersect? #last also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0