[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

scan returning matchdata

T. Onoma

11/10/2004 5:35:00 AM

Wouldn't it be more useful if String#scan returned an array of MatchData?
Assuming that back compatibility should be preserved here, could we at least
get an alternate method that does so, say #mscan ?

Thanks,
T.


2 Answers

dblack

11/10/2004 11:09:00 AM

0

T. Onoma

11/10/2004 1:13:00 PM

0

On Wednesday 10 November 2004 06:09 am, David A. Black wrote:
| Hi --
|
| On Wed, 10 Nov 2004, trans. (T. Onoma) wrote:
| > Wouldn't it be more useful if String#scan returned an array of MatchData?
|
| I don't think so; most of the time, for me anyway, the array elements
| are directly useful, and if they were returned embedded in a MatchData
| object, I'd just end up having to dig them out.

Right. The only caveat being that an "mscan" can do thinks #scan cannot. So
using it would be better even if it meant slightly more "digging" in common
cases. But having a separate method works just as well for me...

| > Assuming that back compatibility should be preserved here, could we at
| > least get an alternate method that does so, say #mscan ?
|
| It's pretty easy:
|
| def mscan(str,re)
| m = []
| str.scan(re) { m << $~ }
| m
| end
|
|

Bless you, David! Worked like a charm. I had no idea one could do it this way
--quite a relief.

T.