Change Proposal for "String#word_wrap" (Ruby on Rails - ActionView::Helpers::TextHelper)

  • Thread starter Wolfgang Nádasi-Donner
  • Start date
W

Wolfgang Nádasi-Donner

Hi!

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

The Method ist defined as
(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top