[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

David Garamond

11/20/2003 11:30:00 AM

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


2 Answers

matz

11/20/2003 11:58:00 AM

0

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.


Florian Gross

11/21/2003 12:35:00 AM

0

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