inspect()
public
Returns a string containing a human-readable representation of
obj. If not overridden and no instance variables, uses the to_s method
to generate the string. obj. If not overridden, uses the to_s method
to generate the string.
[ 1, 2, 3..4, 'five' ].inspect
Time.new.inspect
Show source
static VALUE
rb_obj_inspect(VALUE obj)
{
extern int rb_obj_basic_to_s_p(VALUE);
if (TYPE(obj) == T_OBJECT && rb_obj_basic_to_s_p(obj)) {
int has_ivar = 0;
VALUE *ptr = ROBJECT_IVPTR(obj);
long len = ROBJECT_NUMIV(obj);
long i;
for (i = 0; i < len; i++) {
if (ptr[i] != Qundef) {
has_ivar = 1;
break;
}
}
if (has_ivar) {
VALUE str;
const char *c = rb_obj_classname(obj);
str = rb_sprintf("-<%s:%p", c, (void*)obj);
return rb_exec_recursive(inspect_obj, obj, str);
}
return rb_any_to_s(obj);
}
return rb_funcall(obj, rb_intern("to_s"), 0, 0);
}