Returns an array containing match strings for which block gives
true. MatchData#select will be
removed from Ruby 1.9.
m=/(.)(.)(\d+)(\d)/.match("THX1138: The Movie")pm.select{|x|/X/=~x}#=> ["HX1138", "X"]
/*
* call-seq:
* mtch.select{|obj| block} => array
*
* Returns an array containing match strings for which <em>block</em>
* gives <code>true</code>. MatchData#select will be removed from Ruby 1.9.
*
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
* p m.select{|x| /X/ =~ x} #=> ["HX1138", "X"]
*/
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 {
struct re_registers *regs;
VALUE target;
VALUE result = rb_ary_new();
int i;
int taint = OBJ_TAINTED(match);
match_check(match);
regs = RMATCH(match)->regs;
target = RMATCH(match)->str;
for (i=0; i<regs->num_regs; i++) {
VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]);
if (taint) OBJ_TAINT(str);
if (RTEST(rb_yield(str))) {
rb_ary_push(result, str);
}
}
return result;
}
}