Hi!
I posted this first in comp.lang.ruby, but I think, this here is the
better place. I cannot tell more details, because I''m not a Rails user.
I recognized this method by a hint in the german Ruby forum.
The Method "String#word_wrap" is 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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---