Dan Zwell
8/7/2007 6:52:00 PM
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 = "<someTag>" + y + "</someTag>" 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 "<tag>" + y leave
> off the \n so the output is
> <tag>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