From: Adam Prescott Date: 2011-09-20T23:52:17+09:00 Subject: Re: appending \n to each element in an array --0015174794a4045b4d04ad608231 Content-Type: text/plain; charset=UTF-8 > > I want to put a newline at the end of each phrase in the array. >> words = %w[some of my favourite words] => ["some", "of", "my", "favourite", "words"] >> words.map! { |word| "#{word}\n" } => ["some\n", "of\n", "my\n", "favourite\n", "words\n"] >> words => ["some\n", "of\n", "my\n", "favourite\n", "words\n"] Check http://www.ruby-doc.org/core for the methods #map and #map!. There is also the option of using #each and modifying each string in-place as you iterate. >> words = %w[some of my favourite words] => words.each { |word| word << "\n" } However, modifying elements while iterating with #each can make your life harder, so you should stick to map! to modify the array in-place. --0015174794a4045b4d04ad608231--