> "Kroeger Simon (ext)" <simon.kroeger.ext siemens.com> wrote:
> Hmm, nice, just one little thing:
> 
> str = '12345678901234567890'
> puts str.wrap_to( 10 )
> puts
> puts str.wrap_to( 5 )
> 
> output:
> 
> 1234567890
> 1234567890
> 
> 12345
> 78901
> 34567
> 890
> 
> it 'eats' chars...
> 
> cheers
> 
> Simon

Hmmm.... Here is my quick fix for him ...

class String
     def wrap_to( col_width )
         str = self.gsub( /(\S{#{col_width}})(?=\S)/, '\1 ' )
         str.scan(/(.{1,#{col_width}})(?:\s+|$)/).flatten.join( "\n" )
     end
end