Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallison/3205 to your computer and use it in GitHub Desktop.
Save hallison/3205 to your computer and use it in GitHub Desktop.
Array to String with commas and "and" before the last element
array = ["one","two","three","four","five"]
join = array[0..-2].join(', ') + " and " + array[-1].to_s + " are numbers that belongs to the array of integers."
puts join
# "one, two, three, four and five are numbers that belongs to the array of integers."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment