diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-23 08:26:08 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-23 08:26:08 +0000 |
commit | 18ee9451746f5a60817e944209caeda9dacc3776 (patch) | |
tree | 7cd63989fb038a8112d5d02580f6c866740212ed /re.c | |
parent | fdf213b71a4a9d1a48708516c6cfc6cc85da7c74 (diff) | |
download | ruby-18ee9451746f5a60817e944209caeda9dacc3776.tar.gz |
* re.c (match_inspect): MatchData#inspect implemented.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -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); } |