ruby-changes:17061
From: akr <ko1@a...>
Date: Fri, 20 Aug 2010 10:41:11 +0900 (JST)
Subject: [ruby-changes:17061] Ruby:r29058 (trunk): * ext/pathname/pathname.c (path_expand_path): Pathname#expand_path
akr 2010-08-20 10:40:51 +0900 (Fri, 20 Aug 2010) New Revision: 29058 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29058 Log: * ext/pathname/pathname.c (path_expand_path): Pathname#expand_path translated from pathname.rb. Modified files: trunk/ChangeLog trunk/ext/pathname/lib/pathname.rb trunk/ext/pathname/pathname.c trunk/test/pathname/test_pathname.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29057) +++ ChangeLog (revision 29058) @@ -1,3 +1,8 @@ +Fri Aug 20 10:40:04 2010 Tanaka Akira <akr@f...> + + * ext/pathname/pathname.c (path_expand_path): Pathname#expand_path + translated from pathname.rb. + Thu Aug 19 22:44:56 2010 Nobuyoshi Nakada <nobu@r...> * tool/make-snapshot (usage): add usage. Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 29057) +++ ext/pathname/lib/pathname.rb (revision 29058) @@ -512,9 +512,6 @@ class Pathname # * File * - # See <tt>File.expand_path</tt>. - def expand_path(*args) self.class.new(File.expand_path(@path, *args)) end - # See <tt>File.split</tt>. Returns the #dirname and the #basename in an # Array. def split() File.split(@path).map {|f| self.class.new(f) } end Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 29057) +++ ext/pathname/pathname.c (revision 29058) @@ -460,6 +460,21 @@ } /* + * See <tt>File.expand_path</tt>. + */ +static VALUE +path_expand_path(int argc, VALUE *argv, VALUE self) +{ + VALUE str = get_strpath(self); + VALUE dname; + if (rb_scan_args(argc, argv, "01", &dname) == 0) + str = rb_funcall(rb_cFile, rb_intern("expand_path"), 1, str); + else + str = rb_funcall(rb_cFile, rb_intern("expand_path"), 2, str, dname); + return rb_class_new_instance(1, &str, rb_obj_class(self)); +} + +/* * == Pathname * * Pathname represents a pathname which locates a file in a filesystem. @@ -681,4 +696,5 @@ rb_define_method(rb_cPathname, "basename", path_basename, -1); rb_define_method(rb_cPathname, "dirname", path_dirname, 0); rb_define_method(rb_cPathname, "extname", path_extname, 0); + rb_define_method(rb_cPathname, "expand_path", path_expand_path, -1); } Index: test/pathname/test_pathname.rb =================================================================== --- test/pathname/test_pathname.rb (revision 29057) +++ test/pathname/test_pathname.rb (revision 29058) @@ -926,6 +926,14 @@ assert_equal(".ext", Pathname("basename.ext").extname) end + def test_expand_path + assert_equal(Pathname("/a"), Pathname("/a").expand_path) + assert_equal(Pathname("/a"), Pathname("a").expand_path("/")) + assert_equal(Pathname("/a"), Pathname("a").expand_path(Pathname("/"))) + assert_equal(Pathname("/b"), Pathname("/b").expand_path(Pathname("/a"))) + assert_equal(Pathname("/a/b"), Pathname("b").expand_path(Pathname("/a"))) + end + def test_split assert_equal([Pathname("dirname"), Pathname("basename")], Pathname("dirname/basename").split) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/