From: "David A. Black" Date: 2007-08-18T04:50:36+09:00 Subject: Re: removing something from the end of each item in an array Hi -- On Sat, 18 Aug 2007, Jano Svitok wrote: > On 8/17/07, Chris Carter wrote: >> On 8/17/07, Simon Schuster wrote: >>> in this case a "\n"... >>> >>> ["blah\n", "la\n", "hooray\n"] >>> >>> array.collect { |x| x - "\n" } doesn't work, and I can't manage to >>> find any methods which might do the trick.. pretty basic, but I'm >>> still a beginner! thanks. >>> >>> >> >> array.map {|x| x.chomp } will strip whitespace including new-lines. > > If you by chance want to do that in place, use map! instead of map. Or each and chomp! which will prevent you from creating extra string objects. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)