diff --git a/ChangeLog b/ChangeLog index a606674285..bdef1013ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Aug 13 22:48:39 2010 Tanaka Akira + + * ext/pathname/pathname.c (path_truncate): Pathname#truncate translated + from pathname.rb. + Fri Aug 13 16:11:36 2010 Nobuyoshi Nakada * lib/test/unit.rb (MiniTest::Unit.new): extend before initialize. diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 035204e650..d1a7b5c856 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -512,9 +512,6 @@ end class Pathname # * File * - # See File.truncate. Truncate the file to +length+ bytes. - def truncate(length) File.truncate(@path, length) end - # See File.utime. Update the access and modification times. def utime(atime, mtime) File.utime(atime, mtime, @path) end diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index f98093ff87..a1d260f3ad 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -405,6 +405,15 @@ path_make_symlink(VALUE self, VALUE old) return rb_funcall(rb_cFile, rb_intern("symlink"), 2, old, get_strpath(self)); } +/* + * See File.truncate. Truncate the file to +length+ bytes. + */ +static VALUE +path_truncate(VALUE self, VALUE length) +{ + return rb_funcall(rb_cFile, rb_intern("truncate"), 2, get_strpath(self), length); +} + /* * == Pathname * @@ -622,4 +631,5 @@ Init_pathname() rb_define_method(rb_cPathname, "stat", path_stat, 0); rb_define_method(rb_cPathname, "lstat", path_lstat, 0); rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1); + rb_define_method(rb_cPathname, "truncate", path_truncate, 1); }