inspect()
public
Show the name of the underlying method.
"cat".method(:count).inspect
Show source
/*
* call-seq:
* meth.to_s => string
* meth.inspect => string
*
* Show the name of the underlying method.
*
* "cat".method(:count).inspect #=> "#<Method: String#count>"
*/
static VALUE
method_inspect(method)
VALUE method;
{
struct METHOD *data;
VALUE str;
const char *s;
const char *sharp = "#";
Data_Get_Struct(method, struct METHOD, data);
str = rb_str_buf_new2("#<");
s = rb_obj_classname(method);
rb_str_buf_cat2(str, s);
rb_str_buf_cat2(str, ": ");
if (FL_TEST(data->klass, FL_SINGLETON)) {
VALUE v = rb_iv_get(data->klass, "__attached__");
if (data->recv == Qundef) {
rb_str_buf_append(str, rb_inspect(data->klass));
}
else if (data->recv == v) {
rb_str_buf_append(str, rb_inspect(v));
sharp = ".";
}
else {
rb_str_buf_append(str, rb_inspect(data->recv));
rb_str_buf_cat2(str, "(");
rb_str_buf_append(str, rb_inspect(v));
rb_str_buf_cat2(str, ")");
sharp = ".";
}
}
else {
rb_str_buf_cat2(str, rb_class2name(data->rklass));
if (data->rklass != data->klass) {
rb_str_buf_cat2(str, "(");
rb_str_buf_cat2(str, rb_class2name(data->klass));
rb_str_buf_cat2(str, ")");
}
}
rb_str_buf_cat2(str, sharp);
rb_str_buf_cat2(str, rb_id2name(data->oid));
rb_str_buf_cat2(str, ">");
return str;
}