Forum: Ruby Change Proposal for "String#word_wrap" (Ruby on Rails - Acti

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A131b672fdbd2a58dce12031ad78b121?d=identicon&s=25 Wolfgang Nádasi-Donner (wonado)
on 2007-02-04 13:35
(Received via mailing list)

Hope this is the right place (I'm not a Ruby on Rails user).

The Method ist defined as

def word_wrap(text, line_width = 80)
   text.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/,

The sense of the part 'gsub(/\n/, "\n\n")' is not visible for me,
newlines will be removed in the next step by '\s+'.

I made some tests (Ruby, not Ruby on Rails) and couldn't find any
difference to
the following definition:

def word_wrap(text, line_width = 80)
   text.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip

Wolfgang Nádasi-Donner
Ff9e18f0699bf079f1fc91c8d4506438?d=identicon&s=25 James Britt (Guest)
on 2007-02-04 16:39
(Received via mailing list)
Wolfgang Nádasi-Donner wrote:
> Hi!
> Hope this is the right place (I'm not a Ruby on Rails user).

Rails topics are better addressed on the Rails mailing list.

List info may be found at

James Britt

"I never dispute another person's delusions, just their facts."
   - Len Bullard
This topic is locked and can not be replied to.