From b8148f45947eee7461986536114949556f4eda40 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 19 Jun 2000 08:38:11 +0000 Subject: 2000-06-19 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'file.c') diff --git a/file.c b/file.c index 29cea5471d..a5db21ddcc 100644 --- a/file.c +++ b/file.c @@ -251,6 +251,53 @@ rb_stat_ctime(self) return rb_time_new(get_stat(self)->st_ctime, 0); } +static VALUE +rb_stat_inspect(self) + VALUE self; +{ + VALUE str; + int i; + struct { + char *name; + VALUE (*func)(); + } member[] = { + {"dev", rb_stat_dev}, + {"ino", rb_stat_ino}, + {"mode", rb_stat_mode}, + {"nlink", rb_stat_nlink}, + {"uid", rb_stat_uid}, + {"gid", rb_stat_gid}, + {"rdev", rb_stat_rdev}, + {"size", rb_stat_size}, + {"blksize", rb_stat_blksize}, + {"blocks", rb_stat_blocks}, + {"atime", rb_stat_atime}, + {"mtime", rb_stat_mtime}, + {"ctime", rb_stat_ctime}, + }; + + str = rb_str_new2("#<"); + rb_str_cat2(str, rb_class2name(CLASS_OF(self))); + rb_str_cat2(str, " "); + + for (i = 0; i < sizeof(member)/sizeof(member[0]); i++) { + VALUE str2; + char *p; + + if (i > 0) { + rb_str_cat2(str, ", "); + } + rb_str_cat2(str, member[i].name); + rb_str_cat2(str, "="); + str2 = rb_inspect((*member[i].func)(self)); + rb_str_append(str, str2); + } + rb_str_cat2(str, ">"); + OBJ_INFECT(str, self); + + return str; +} + static int rb_stat(file, st) VALUE file; @@ -2216,6 +2263,8 @@ Init_File() rb_define_method(rb_cStat, "mtime", rb_stat_mtime, 0); rb_define_method(rb_cStat, "ctime", rb_stat_ctime, 0); + rb_define_method(rb_cStat, "inspect", rb_stat_inspect, 0); + rb_define_method(rb_cStat, "ftype", rb_stat_ftype, 0); rb_define_method(rb_cStat, "directory?", rb_stat_d, 0); -- cgit v1.2.3