# Why no MatchData#match?

**URL:** <https://www.ruby-forum.com/t/why-no-matchdata-match/104607>\
**Category:** Ruby\
**Created:** [May 20, 2007, 4:17pm UTC](https://www.ruby-forum.com/t/why-no-matchdata-match/104607 "2007-05-20T16:17:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [May 20, 2007, 4:17pm UTC](https://www.ruby-forum.com/t/why-no-matchdata-match/104607/1 "2007-05-20T16:17:52Z")

</div>

I use MatchData infrequently enough that I keep being thrown by the  
lack of a #match method, to go along with #pre\_match and #post\_match.  
#[0] simply isn’t as self-documenting.

martin

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [May 20, 2007, 4:40pm UTC](https://www.ruby-forum.com/t/why-no-matchdata-match/104607/2 "2007-05-20T16:40:54Z")

</div>

On 20.05.2007 16:16, Martin DeMello wrote:

> I use MatchData infrequently enough that I keep being thrown by the  
> lack of a #match method, to go along with #pre\_match and #post\_match.  
> #[0] simply isn’t as self-documenting.

Probably because “match” sounds like the MD would be able to match again  
(like Regexp.match). If you can come up with an unambiguous name I’d  
make it a RCR.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [May 20, 2007, 4:56pm UTC](https://www.ruby-forum.com/t/why-no-matchdata-match/104607/3 "2007-05-20T16:56:23Z")

</div>

Robert K. wrote:

> If you can come up with an unambiguous name I’d make it a RCR.

Maybe “MatchData#matched” makes sense.

irb(main):009:0\> md = “Hugo is a great dancer!”.match(/great/)  
=\> #MatchData:0x2b35644  
irb(main):010:0\> md.pre\_match  
=\> “Hugo is a "  
irb(main):011:0\> md.matched  
=\> “great”  
irb(main):012:0\> md.post\_match  
=\> " dancer!”

Wolfgang NÃ¡dasi-Donner

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [May 20, 2007, 8:41pm UTC](https://www.ruby-forum.com/t/why-no-matchdata-match/104607/4 "2007-05-20T20:41:07Z")

</div>

On May 20, 10:40 am, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 20.05.2007 16:16, Martin DeMello wrote:
> 
> > I use MatchData infrequently enough that I keep being thrown by the  
> > lack of a #match method, to go along with #pre\_match and #post\_match.  
> > #[0] simply isn’t as self-documenting.
> 
> Probably because “match” sounds like the MD would be able to match again  
> (like Regexp.match). If you can come up with an unambiguous name I’d  
> make it a RCR.

Long considered this, and I’ve come to think it doesn’t matter. In  
everyday language we use “match” in multiple contexts, including verb  
and noun. I think it’s okay if Ruby does too.

T.
