Library consistency

Hi, guys,

Just a sugestion: I think it would be a nice idea if all library
calls that return a regexp match could return a MatchData object. Today,
/regexp/.match, string.gsub and string.scan all return diferent things.
Is that a bad idea for some reason?

Bye,
Maurício

Each of these has a different purpose, though. Just looking at the
two which appear to be related (gsub isn’t related because it’s
supposed to return a replaced string):

% ruby -e 'puts /(…)(…)/.match(“cruel world”)'
crue
cr
ue

% ruby -e 'puts “cruel world”.scan(/(…)(…)/).join("\n")'
cr
ue
l
wo

Note that the latter actually returns [[‘cr’, ‘ue’], ['l ', ‘wo’]].
It might be useful to be able to do:

/(…)(…)/.scan(“cruel world”)

Which returns an array of MatchData.

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.01 at 16.01.28

···

On Sat, 2 Nov 2002 05:57:28 +0900, Maurício wrote:

Hi, guys,

Just a sugestion: I think it would be a nice idea if all library
calls that return a regexp match could return a MatchData object.
Today, /regexp/.match, string.gsub and string.scan all return
diferent things. Is that a bad idea for some reason?

You’re right. When I said that I want all of those functions to
return the same information, I actually tried to say that scan and gsub
should pass a MatchData to the block, i.e., in

“alksjhsa”.gsub(/…/ix){|match|
}

I would like match to be a MatchData. Here we need to use $1, $2 etc.
and that’s not always the best way to do it, in my opinion.

Austin Ziegler wrote:

···

On Sat, 2 Nov 2002 05:57:28 +0900, Maurício wrote:

Hi, guys,

Just a sugestion: (…)

Each of these has a different purpose, though. (…)