summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-13 13:50:31 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-13 13:50:31 +0000
commite13d02d746bf17226c6cb6b1f68ab7fa27c31fbf (patch)
tree0f172aee9a286081cc8ffd51bfd476c10ed56c67 /lib
parent4202879723a9916af9c44bca00b804d2c8f979b0 (diff)
downloadruby-e13d02d746bf17226c6cb6b1f68ab7fa27c31fbf.tar.gz
ruby-e13d02d746bf17226c6cb6b1f68ab7fa27c31fbf.tar.xz
ruby-e13d02d746bf17226c6cb6b1f68ab7fa27c31fbf.zip
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/pathname.rb13
1 files changed, 12 insertions, 1 deletions
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
+ # <i>repl</i>.
+ #
+ # If self has no extension part, <i>repl</i> 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)