inspect()
public
Return a string describing this IO object.
Show source
static VALUE
rb_io_inspect(VALUE obj)
{
rb_io_t *fptr;
const char *cname;
char fd_desc[4+sizeof(int)*3];
const char *path;
const char *st = "";
fptr = RFILE(rb_io_taint_check(obj))->fptr;
if (!fptr) return rb_any_to_s(obj);
cname = rb_obj_classname(obj);
if (NIL_P(fptr->pathv)) {
if (fptr->fd < 0) {
path = "";
st = "(closed)";
}
else {
snprintf(fd_desc, sizeof(fd_desc), "fd %d", fptr->fd);
path = fd_desc;
}
}
else {
path = RSTRING_PTR(fptr->pathv);
if (fptr->fd < 0) {
st = " (closed)";
}
}
return rb_sprintf("#<%s:%s%s>", cname, path, st);
}