Mark Hubbart wrote:
> On 11/13/05, daz wrote:
> > Tom Reilly wrote:
> > > Regexp error?
> > > Page 538 Programming Ruby
> > >
> > > m = /(.)(.)(\d+)(\d)/.select("TXH1138: The Movie")
> > > p m.to_a
> > >
> > >
> > > rb_tmp.rb:1: private method `select' called for /(.)(.)(\d+)(\d)/:Regexp
> > > (NoMethodError)
> > >  >Exit code: 1
> > >
> > >
> > > Why should there be a NoMethodError for select?
> > >
> >
> >
> > There's no method Regexp#select, AFAIK.
> >
> > Is that a second edition misprint?
>
> 538 is the section on MatchData, which has a #select. Regexp has no
> #select method.
>

So is the example the same as in the rdoc?:
http://www.ruby-doc.org/core/classes/MatchData.html#M000496

  m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
  m.to_a               #=> ["HX1138", "H", "X", "113", "8"]
  m.select(0, 2, -2)   #=> ["HX1138", "X", "113"]

i.e. it creates a MatchData object before calling select?

Therefore the confusion is due to a bug in MatchData#select -

 :in `select': wrong number of arguments (3 for 0) (ArgumentError)

<re.c>

static VALUE
match_select(argc, argv, match)
    int argc;
    VALUE *argv;
    VALUE match;
{
    if (argc > 0) {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
    }
    else {      [...]

    rb_cMatch  = rb_define_class("MatchData", rb_cObject);
[...]
    rb_define_method(rb_cMatch, "select", match_select, -1);

</re.c>


daz