Forum: Ruby why no MatchData#match ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae16cb4f6d78e485b04ce1e821592ae5?d=identicon&s=25 Martin DeMello (Guest)
on 2007-05-20 16:17
(Received via mailing list)
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
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-05-20 16:40
(Received via mailing list)
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
A131b672fdbd2a58dce12031ad78b121?d=identicon&s=25 Wolfgang Nádasi-Donner (wonado)
on 2007-05-20 16:56
Robert Klemme 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
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Trans (Guest)
on 2007-05-20 20:41
(Received via mailing list)
On May 20, 10:40 am, Robert Klemme <shortcut...@googlemail.com> 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.
This topic is locked and can not be replied to.