From: Gennady Bystritsky Date: 2009-03-05T17:30:55+09:00 Subject: Re: Cut a string each 80 character > -----Original Message----- > From: Leo [mailto:minilith@gmail.com] > Sent: Wednesday, March 04, 2009 9:53 PM > To: ruby-talk ML > Subject: Re: Cut a string each 80 character > > > string.scan(%r{.{1,80}}).map { |_chunk| > >   _chunk + '
' > > } > > Isn't that pretty much the same as: > > string.gsub(%r{.{1,80}}, "\\0
") > > leo. Almost. The latter produces a string with "
" after every 80 chars, while the former returns an array of strings 86 chars long each. What is more appropriate depends on a context. Say, you may want to decorate chunks even further by passing them through some other methods (on the other hand, grep with a block may be used for that as well). The latter may be faster, though. Thanks for bringing it up, Gennady.