Error in MatchData docs

"Ted Behling" <[email protected]> Fri, 14 Nov 2008 16:08:32 -0500
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <[email protected]>
Hello,

I wanted to point out an error I found in the documentation for the
MatchData class, visible at
http://ruby-doc.org/core/classes/MatchData.html .  Please advise if I
should post this elsewhere (such as a bug tracker).

Under the heading "mtch.captures => array", that page says:

    Returns the array of captures; equivalent to mtch.to_a. 

However, that is demonstrably not the case, at least in Ruby 1.8.5.
MatchData#captures is different from MatchData#to_a in that to_a's first
element is the entire matched string, as in:

    irb(main):001:0> /(.)(.)(.)/.match('abc').captures
    => ["a", "b", "c"]
    irb(main):002:0> /(.)(.)(.)/.match('abc').to_a
    => ["abc", "a", "b", "c"]
    irb(main):003:0>

I suggest the verbage be changed to append the text "except that to_a
inserts the matched string as the first array element" after "equivalent
to mtch.to_a". 

Ted Behling
ISP Systems Analyst, Hargray Communications
[email protected]