Xavier Noria
8/17/2007 7:05:00 PM
On Aug 17, 2007, at 8:35 PM, Chris Carter wrote:
> On 8/17/07, Simon Schuster <significants@gmail.com> 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.
That sounds to me as if it meant
%r{\s+\z}
Just in case, if $/ has not been changed chomp removes any trailing
single occurrence of \n, \r, \r\n:
irb(main):005:0> "foo \r\n".chomp
=> "foo "
irb(main):006:0> "foo \n\n".chomp
=> "foo \n"
-- fxn