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

Discussion in 'Ruby' started by Wolfgang Nádasi-Donner, Feb 4, 2007.

  1. 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
     
    Wolfgang Nádasi-Donner, Feb 4, 2007
    #1
    1. Advertising

  2. Wolfgang Nádasi-Donner

    James Britt Guest

    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


    --
    James Britt

    "I never dispute another person's delusions, just their facts."
    - Len Bullard
     
    James Britt, Feb 4, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Aman

    Helpers in Rails

    Bob Aman, Mar 30, 2005, in forum: Ruby
    Replies:
    2
    Views:
    92
    Bob Aman
    Mar 30, 2005
  2. Caspar Bl

    gems, helpers and rails

    Caspar Bl, Aug 13, 2006, in forum: Ruby
    Replies:
    2
    Views:
    127
    Caspar Bl
    Aug 13, 2006
  3. Replies:
    1
    Views:
    115
    Eric Hodel
    Sep 5, 2006
  4. Gerald Bauer
    Replies:
    0
    Views:
    114
    Gerald Bauer
    Feb 25, 2009
  5. T_P

    app/helpers in Rails

    T_P, Nov 28, 2009, in forum: Ruby
    Replies:
    3
    Views:
    104
    Brian Candler
    Nov 29, 2009
Loading...

Share This Page