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.