I have an array
books = ["Title 1", "Title 2", "Title 3"]
I need to iterate through this array and get a variable like this:
@books_read = "Title 1 \n Title 2 \n Title 3"
I tried this bit of code:
books.each do |book|
@books_read += "#{book} \n"
end
puts @books_read
But, the + operator does not concatenate the strings. Any leads on this please.
Cheers!
You can use
join:books.join(" \n ")