# Library consistency

**URL:** <https://rubytalk.org/t/library-consistency/2609>\
**Category:** ruby-talk\
**Created:** [1 November 2002 20:57 UTC](https://rubytalk.org/t/library-consistency/2609 "2002-11-01T20:57:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@Mauricio](https://rubytalk.org/u/Mauricio)\
**Post date:** [1 November 2002 20:57 UTC](https://rubytalk.org/t/library-consistency/2609/1 "2002-11-01T20:57:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler2](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Austin\_Ziegler2](https://rubytalk.org/u/Austin_Ziegler2)\
**Post date:** [1 November 2002 21:10 UTC](https://rubytalk.org/t/library-consistency/2609/2 "2002-11-01T21:10:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Mauricio](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@Mauricio](https://rubytalk.org/u/Mauricio)\
**Post date:** [1 November 2002 21:21 UTC](https://rubytalk.org/t/library-consistency/2609/3 "2002-11-01T21:21:10Z")

</div>

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. (…)
