Method: MatchData#names
- Defined in:
- re.c
#names ⇒ Object
Returns an array of the capture names (see Named Captures):
m = /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge")
# => #<MatchData "hog" foo:"h" bar:"o" baz:"g">
m.names # => ["foo", "bar", "baz"]
m = /foo/.match('foo') # => #<MatchData "foo">
m.names # => [] # No named captures.
Equivalent to:
m = /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge")
m.regexp.names # => ["foo", "bar", "baz"]
1162 1163 1164 1165 1166 1167 1168 1169 |
# File 're.c', line 1162
static VALUE
match_names(VALUE match)
{
match_check(match);
if (NIL_P(RMATCH(match)->regexp))
return rb_ary_new_capa(0);
return rb_reg_names(RMATCH(match)->regexp);
}
|