From: Dan Zwell Date: 2007-08-08T03:52:16+09:00 Subject: Re: array.each puzzle from new ruby-er Gani Ruthellen wrote: >> Know that this is actually rebinding the local variable y to point to a >> new object, not modifying the old object. If your goal was to modify the >> array "lines", you should change "lines.each" to "lines.map" and make >> sure you end the block with a statement that returns the modified y. >> >> perhaps: >> lines.map do |y| >> y = y.chomp("\x15").chomp >> y = "" + y + "" if y =~ /^\*\*\*/ >> y >> end >> >> >> Dan > > Sorry, actually doing each_with_index do |y,ind| (etc) and specifically > setting lines[ind] = y > but my original question remains: how do i make the "" + y leave > off the \n so the output is > text of y > Thanks again Sorry, I thought that would work but didn't test it. "y.lstrip" will do what you want, but will also will strip leading whitespace, which might not be okay. If not, "y[1..-1]" should suffice--this will return y from the second character on. y = y[1..-1] if y =~ /^\n/ Dan