From: Robert Klemme Date: 2004-12-14T00:37:23+09:00 Subject: Re: Help writing a each_unique method "trans. (T. Onoma)" schrieb im Newsbeitrag news:200412131012.46675.transami@runbox.com... > P.S. Does anyone have a really good String#word_wrap method? I wrote one but > it isn't so good b/c it strip newlines. What about class String def word_wrap!(n = 80) raise ArgumentError, "Wrap margin too low: #{n}" if n <= 2 gsub!( Regexp.new( "(.{1,#{n-1}}\\w)\\b\\s*" ), "\\1\n") end def word_wrap(n = 80) c = dup c.word_wrap! n c end end Kind regards robert