From ec5bb26fa031288fd8f935443805f68e5637ee75 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 9 Aug 2010 13:15:49 +0000 Subject: * ext/pathname/pathname.c (path_open): Pathname#open translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/pathname/lib/pathname.rb | 5 ----- ext/pathname/pathname.c | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'ext/pathname') diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index b685309e7c..197c9e6bf4 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -512,11 +512,6 @@ end class Pathname # * File * - # See File.open. Opens the file for reading or writing. - def open(*args, &block) # :yield: file - File.open(@path, *args, &block) - end - # See File.readlink. Read symbolic link. def readlink() self.class.new(File.readlink(@path)) end diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index fb023f334e..f7686717d8 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -336,6 +336,25 @@ path_make_link(VALUE self, VALUE old) return rb_funcall(rb_cFile, rb_intern("link"), 2, old, get_strpath(self)); } +/* + * See File.open. Opens the file for reading or writing. + */ +static VALUE +path_open(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n; + + args[0] = get_strpath(self); + n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]); + if (rb_block_given_p()) { + return rb_block_call(rb_cFile, rb_intern("open"), 1+n, args, 0, 0); + } + else { + return rb_funcall2(rb_cFile, rb_intern("open"), 1+n, args); + } +} + /* * == Pathname * @@ -547,4 +566,5 @@ Init_pathname() rb_define_method(rb_cPathname, "fnmatch?", path_fnmatch, -1); rb_define_method(rb_cPathname, "ftype", path_ftype, 0); rb_define_method(rb_cPathname, "make_link", path_make_link, 1); + rb_define_method(rb_cPathname, "open", path_open, -1); } -- cgit v1.2.3