inspect()
public
Returns a printable version of mtch.
puts /.$/.match("foo").inspect
puts /(.)(.)(.)/.match("foo").inspect
puts /(.)(.)?(.)/.match("fo").inspect
Show source
/*
* call-seq:
* mtch.inspect => str
*
* Returns a printable version of <i>mtch</i>.
*
* puts /.$/.match("foo").inspect
*
*
* puts /(.)(.)(.)/.match("foo").inspect
*
*
* puts /(.)(.)?(.)/.match("fo").inspect
*
*
*/
static VALUE
match_inspect(VALUE match)
{
const char *cname = rb_obj_classname(match);
VALUE str;
int i;
struct re_registers *regs = RMATCH(match)->regs;
int num_regs = regs->num_regs;
str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, cname);
for (i = 0; i < num_regs; i++) {
VALUE v;
rb_str_buf_cat2(str, " ");
if (0 < i) {
char buf[sizeof(i)*3+1];
snprintf(buf, sizeof(buf), "%d", i);
rb_str_buf_cat2(str, buf);
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;
}