behaviour change of String#gsub(pattern) {|m| ... } for ruby 1.9/ruby2?

Discussion in 'Ruby' started by David Garamond, Nov 20, 2003.

  1. String#gsub(pattern) {|m| ... }

    It really would be nice to get match data in 'm', but this would surely
    break _a lot_ of scripts. How about String#regsub, #regsub!, #resub,
    #resub! ? What do others think?

    --
    dave
    David Garamond, Nov 20, 2003
    #1
    1. Advertising

  2. Hi,

    In message "behaviour change of String#gsub(pattern) {|m| ... } for ruby 1.9/ruby2?"
    on 03/11/20, David Garamond <lists@zara.6.isreserved.com> writes:

    |String#gsub(pattern) {|m| ... }
    |
    |It really would be nice to get match data in 'm', but this would surely
    |break _a lot_ of scripts. How about String#regsub, #regsub!, #resub,
    |#resub! ? What do others think?

    Sounds nice. The only reason for the current behavior is that sub
    predates MatchData. But we have to define migration path.

    matz.
    Yukihiro Matsumoto, Nov 20, 2003
    #2
    1. Advertising

  3. Re: behaviour change of String#gsub(pattern) {|m| ... } for ruby1.9/ruby2?

    Yukihiro Matsumoto wrote:

    > Hi,


    Moin!

    > |String#gsub(pattern) {|m| ... }
    > |
    > |It really would be nice to get match data in 'm', but this would surely
    > |break _a lot_ of scripts. How about String#regsub, #regsub!, #resub,
    > |#resub! ? What do others think?
    >
    > Sounds nice. The only reason for the current behavior is that sub
    > predates MatchData. But we have to define migration path.


    I like this, because matz told me I shouldn't be using $1 in the
    gsub-block and there's no way to not do so right now. :)

    Add a MatchData#to_str and it should work for most cases. We could give
    a warning for cases where scripts would still be broken by this chance.

    Regards,
    Florian Gross
    Florian Gross, Nov 21, 2003
    #3
    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. Guest
    Replies:
    34
    Views:
    376
    Jim Freeze
    Aug 28, 2003
  2. Lionel Thiry

    [ruby2] will '@@' disapear in ruby2?

    Lionel Thiry, Mar 12, 2005, in forum: Ruby
    Replies:
    12
    Views:
    166
    Lionel Thiry
    Mar 17, 2005
  3. Lionel Thiry
    Replies:
    3
    Views:
    101
    Lionel Thiry
    Apr 11, 2005
  4. aurelianito

    gsub and gsub! are inconsistent

    aurelianito, Nov 8, 2005, in forum: Ruby
    Replies:
    9
    Views:
    154
    Robert Klemme
    Nov 9, 2005
  5. Craig Jolicoeur
    Replies:
    9
    Views:
    140
    7stud --
    Apr 29, 2009
Loading...

Share This Page