# Change Proposal for "String#word\_wrap" (Ruby on Rails - Acti

**URL:** <https://www.ruby-forum.com/t/change-proposal-for-string-word-wrap-ruby-on-rails-acti/84429>\
**Category:** Ruby\
**Created:** [February 4, 2007, 1:35pm UTC](https://www.ruby-forum.com/t/change-proposal-for-string-word-wrap-ruby-on-rails-acti/84429 "2007-02-04T13:35:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wonado](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wonado](https://www.ruby-forum.com/u/wonado)\
**Post date:** [February 4, 2007, 1:35pm UTC](https://www.ruby-forum.com/t/change-proposal-for-string-word-wrap-ruby-on-rails-acti/84429/1 "2007-02-04T13:35:29Z")

</div>

Hi!

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

The Method ist defined as  
([ActionView::Helpers::TextHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M000616)):

def word\_wrap(text, line\_width = 80)  
text.gsub(/\n/, “\n\n”).gsub(/(.{1,#{line\_width}})(\s+|$)/,  
“\1\n”).strip  
end

The sense of the part ‘gsub(/\n/, “\n\n”)’ is not visible for me,  
because  
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  
end

Wolfgang Nádasi-Donner

---

<div class="post-metadata">

**Author:** ![wonado](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wonado](https://www.ruby-forum.com/u/wonado)\
**Post date:** [February 4, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/change-proposal-for-string-word-wrap-ruby-on-rails-acti/84429/2 "2007-02-04T16:39:46Z")

</div>

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 [http://www.rubyonrails.org](http://www.rubyonrails.org)

–  
James B.

“I never dispute another person’s delusions, just their facts.”

- Len Bullard
