1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2004-01-10 13:46:21 +00:00
parent 33a899f09b
commit 53157197d2
2 changed files with 28 additions and 0 deletions

View file

@ -1,3 +1,7 @@
Sat Jan 10 22:46:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (dir_inspect): new method, Dir#inspect. [ruby-dev:22562]
Fri Jan 9 13:14:59 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
* lib/test/unit/collector/dir.rb: do not ignore exceptions(LoadError

24
dir.c
View file

@ -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);