ruby-changes:16817
From: akr <ko1@a...>
Date: Sun, 1 Aug 2010 09:22:40 +0900 (JST)
Subject: [ruby-changes:16817] Ruby:r28812 (trunk): * ext/pathname/pathname.c (path_sub): Pathname#sub translated
akr 2010-08-01 09:22:18 +0900 (Sun, 01 Aug 2010) New Revision: 28812 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28812 Log: * ext/pathname/pathname.c (path_sub): Pathname#sub translated from pathname.rb. Modified files: trunk/ChangeLog trunk/ext/pathname/lib/pathname.rb trunk/ext/pathname/pathname.c Index: ChangeLog =================================================================== --- ChangeLog (revision 28811) +++ ChangeLog (revision 28812) @@ -1,3 +1,8 @@ +Sun Aug 1 09:21:32 2010 Tanaka Akira <akr@f...> + + * ext/pathname/pathname.c (path_sub): Pathname#sub translated + from pathname.rb. + Sun Aug 1 09:12:50 2010 Nobuyoshi Nakada <nobu@r...> * include/ruby/win32.h: latest x86_64 mingw defines stati64. Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 28811) +++ ext/pathname/lib/pathname.rb (revision 28812) @@ -31,25 +31,6 @@ # :startdoc: - # Return a pathname which is substituted by String#sub. - def sub(pattern, *rest, &block) - if block - path = @path.sub(pattern, *rest) {|*args| - begin - old = Thread.current[:pathname_sub_matchdata] - Thread.current[:pathname_sub_matchdata] = $~ - eval("$~ = Thread.current[:pathname_sub_matchdata]", block.binding) - ensure - Thread.current[:pathname_sub_matchdata] = old - end - yield(*args) - } - else - path = @path.sub(pattern, *rest) - end - self.class.new(path) - end - if File::ALT_SEPARATOR SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}" SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/ Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 28811) +++ ext/pathname/pathname.c (revision 28812) @@ -151,6 +151,23 @@ } /* + * Return a pathname which is substituted by String#sub. + */ +static VALUE +path_sub(int argc, VALUE *argv, VALUE self) +{ + VALUE str = get_strpath(self); + + if (rb_block_given_p()) { + str = rb_block_call(str, rb_intern("sub"), argc, argv, 0, 0); + } + else { + str = rb_funcall2(str, rb_intern("sub"), argc, argv); + } + return rb_class_new_instance(1, &str, rb_obj_class(self)); +} + +/* * == Pathname * * Pathname represents a pathname which locates a file in a filesystem. @@ -346,4 +363,5 @@ rb_define_method(rb_cPathname, "to_s", path_to_s, 0); rb_define_method(rb_cPathname, "to_path", path_to_s, 0); rb_define_method(rb_cPathname, "inspect", path_inspect, 0); + rb_define_method(rb_cPathname, "sub", path_sub, -1); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/