新井です。

$ ruby -ve 'p File.stat "/tmp/hoge"'

ruby 1.5.4 (2000-06-05) [i586-linux]
#<File::Stat:0x4011a648>

は、寂しかったので inspect 作りました。

$ ruby -ve 'p File.stat "/tmp/hoge"'

ruby 1.5.4 (2000-06-05) [i586-linux]
#<File::Stat dev=5635, ino=4261, mode=33188, nlink=1, uid=501, gid=100, rdev=0, size=0, blksize=4096, blocks=0, atime=Sat Jun 17 01:35:15 JST 2000, mtime=Sat Jun 17 01:35:15 JST 2000, ctime=Sat Jun 17 01:35:15 JST 2000>

ちょっとウルサイかも?


Fri Jun 16 16:23:35 2000 Koji Arai <JCA02266 / nifty.ne.jp> * file.c (rb_stat_inspect): add for compatibility with ruby-1.4.x. Index: file.c =================================================================== RCS file: /home/cvs/ruby/file.c,v retrieving revision 1.29 diff -u -p -u -r1.29 file.c --- file.c 2000/06/12 07:48:19 1.29 +++ file.c 2000/06/16 16:23:35 @@ -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; @@ -2215,6 +2262,8 @@ Init_File() rb_define_method(rb_cStat, "atime", rb_stat_atime, 0); 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); -- 新井康司 (Koji Arai)