From 53157197d2fc18b2fcef62df05c2fca8707cd979 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 10 Jan 2004 13:46:21 +0000 Subject: * dir.c (dir_inspect): new method, Dir#inspect. [ruby-dev:22562] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dir.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 84b0d21dde..5e9015da69 100644 --- a/dir.c +++ b/dir.c @@ -372,6 +372,29 @@ dir_closed() if (dirp->dir == NULL) dir_closed();\ } while (0) +/* + * call-seq: + * dir.inspect => string + * + * Return a string describing this Dir object. + */ +static VALUE +dir_inspect(dir) + VALUE dir; +{ + struct dir_data *dirp; + + GetDIR(dir, dirp); + if (dirp->path) { + char *c = rb_obj_classname(dir); + int len = strlen(c) + strlen(dirp->path) + 4; + VALUE s = rb_str_new(0, len); + snprintf(RSTRING(s)->ptr, len+1, "#<%s:%s>", c, dirp->path); + return s; + } + return rb_funcall(dir, rb_intern("to_s"), 0, 0); +} + /* * call-seq: * dir.path => string or nil @@ -1502,6 +1525,7 @@ Init_Dir() rb_define_method(rb_cDir,"initialize", dir_initialize, 1); rb_define_method(rb_cDir,"path", dir_path, 0); + rb_define_method(rb_cDir,"inspect", dir_inspect, 0); rb_define_method(rb_cDir,"read", dir_read, 0); rb_define_method(rb_cDir,"each", dir_each, 0); rb_define_method(rb_cDir,"rewind", dir_rewind, 0); -- cgit v1.2.3