liveBook · Manning

Array.join()

As explained in The Well-Grounded Rubyist, Fourth Edition

join is a Ruby Array method that returns a string formed by concatenating the string representations of the array's elements with an optional separator.

Ruby's Array#join transforms an array into a single string by concatenating the string representation of each element. With no argument, elements touch directly; an optional separator is inserted between neighboring elements. section 9.2.4

Formatting a list

Use join(", ") when an array should become readable comma-separated text, such as "abc, def, 123". Choose another separator when the output format calls for a different boundary, such as a hyphen.

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains return values, optional separators, element conversion, and the equivalent * form without pursuing implementation internals.
Examples
Uses mixed strings and integers, comma-space formatting, and hyphen-separated words to demonstrate joining.
What it assumes
Assumes basic arrays and string values while demonstrating how a numeric element participates in string output.
What you can do after
Apply via Ruby's Array#join to produce strings with either direct concatenation or a chosen separator.
How it connects
Connects array transformations with strings and the * operator as an alternative joining syntax.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.