On Tue, 4 Oct 2005, Ben wrote:

> I have a string containing multiple lines that I would like to put
> into a C++ file as a comment:
> desc = ""
> while (line = gets) !~ /^\.$/
>  desc += "#{line}"
> end
>
> I'd like to precede each line with a "//   " to make it a comment, and I'd
> like to wrap each line by the 78th character.
>
> I don't suppose there is any way to do this quick and simple like?
>
> I figure I need to pull out the carriage returns, but then I can't think of
> anything pretty after that.  Any tips?

   harp:~ > cat a.rb
   require 'alib'

   comment = "foobar " * 42

   indented = ALib::Util::columnize comment, 'indent' => '// ', 'width' => 78

   puts(('.' * 77) << 'v')
   puts indented
   puts(('.' * 77) << '^')


   harp:~ > ruby a.rb
   .............................................................................v
   // foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar
   // foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar
   // foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar
   // foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar
   // foobar foobar
   .............................................................................^

hth.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================