From e13d02d746bf17226c6cb6b1f68ab7fa27c31fbf Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 13 Feb 2008 13:50:31 +0000 Subject: * lib/pathname.rb (Pathname#sub_ext): new method. [ruby-list:44608] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/pathname.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pathname.rb b/lib/pathname.rb index e4ca5489c..b2e119db1 100644 --- a/lib/pathname.rb +++ b/lib/pathname.rb @@ -255,11 +255,22 @@ class Pathname end if File::ALT_SEPARATOR - SEPARATOR_PAT = /[#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}]/ + SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}" + SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/ else + SEPARATOR_LIST = "#{Regexp.quote File::SEPARATOR}" SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/ end + # Return a pathname which the extention of the basename is substituted by + # repl. + # + # If self has no extension part, repl is appended. + def sub_ext(repl) + ext = File.extname(@path) + self.class.new(@path.chomp(ext) + repl) + end + # chop_basename(path) -> [pre-basename, basename] or nil def chop_basename(path) base = File.basename(path) -- cgit