1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* re.c (match_inspect): MatchData#inspect implemented.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2007-06-23 08:26:08 +00:00
parent fdf213b71a
commit 18ee945174
2 changed files with 29 additions and 1 deletions

View file

@ -1,3 +1,7 @@
Sat Jun 23 17:18:19 2007 Tanaka Akira <akr@fsij.org>
* re.c (match_inspect): MatchData#inspect implemented.
Sat Jun 23 01:25:40 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_assoc): new method.

26
re.c
View file

@ -1434,6 +1434,30 @@ match_string(VALUE match)
return RMATCH(match)->str; /* str is frozen */
}
static VALUE
match_inspect(VALUE match)
{
char *cname = rb_obj_classname(match);
VALUE str;
int i;
str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, cname);
for (i = 0; i < RMATCH(match)->regs->num_regs; i++) {
VALUE v;
rb_str_buf_cat2(str, " ");
v = rb_reg_nth_match(i, match);
if (v == Qnil)
rb_str_buf_cat2(str, "nil");
else
rb_str_buf_append(str, rb_str_inspect(v));
}
rb_str_buf_cat2(str, ">");
return str;
}
VALUE rb_cRegexp;
static void
@ -2396,6 +2420,6 @@ Init_Regexp(void)
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0);
rb_define_method(rb_cMatch, "to_s", match_to_s, 0);
rb_define_method(rb_cMatch, "inspect", rb_any_to_s, 0); /* in object.c */
rb_define_method(rb_cMatch, "inspect", match_inspect, 0);
rb_define_method(rb_cMatch, "string", match_string, 0);
}