Index: re.c
===================================================================
--- re.c (revision 43916)
+++ re.c (working copy)
@@ -1775,35 +1775,32 @@
return rb_ary_aref(argc, argv, match_to_a(match));
}
-static VALUE
-match_entry(VALUE match, long n)
-{
- /* n should not exceed num_regs */
- return rb_reg_nth_match((int)n, match);
-}
-
-
/*
* call-seq:
*
- * mtch.values_at([index]*) -> array
+ * mtch.values_at(key, ...) -> array
*
- * Uses each index to access the matching values, returning an array of
- * the corresponding matches.
+ * Return an array containing the matches associated with the given keys.
*
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
* m.to_a #=> ["HX1138", "H", "X", "113", "8"]
* m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"]
+ *
+ * m = /(?.+) as (?.+)/.match("Robert Duvall as THX 1138")
+ * m.values_at(:actor, "role") #=> ["Robert Duvall", "THX 1138"]
*/
static VALUE
match_values_at(int argc, VALUE *argv, VALUE match)
{
- struct re_registers *regs;
+ VALUE result = rb_ary_new2(argc);
+ long i;
match_check(match);
- regs = RMATCH_REGS(match);
- return rb_get_values_at(match, regs->num_regs, argc, argv, match_entry);
+ for (i=0; i...)(?...)(?...)(...)?/.match("foobarbaz")
+ assert_equal(["foo", "bar", "baz"], m.values_at(:a, "b", "c"))
end
def test_match_string