mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/pathname.rb (Pathname#sub_ext): new method. [ruby-list:44608]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
800ff52c17
commit
70f25096c0
3 changed files with 27 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Feb 13 22:46:36 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/pathname.rb (Pathname#sub_ext): new method. [ruby-list:44608]
|
||||
|
||||
Wed Feb 13 21:50:32 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* proc.c (proc_curry): new method. [ruby-dev:33676]
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -381,6 +381,17 @@ class TestPathname < Test::Unit::TestCase
|
|||
def pathsub(path, pat, repl) Pathname.new(path).sub(pat, repl).to_s end
|
||||
defassert(:pathsub, "a.o", "a.c", /\.c\z/, ".o")
|
||||
|
||||
def pathsubext(path, repl) Pathname.new(path).sub_ext(repl).to_s end
|
||||
defassert(:pathsubext, 'a.o', 'a.c', '.o')
|
||||
defassert(:pathsubext, 'a.o', 'a.c++', '.o')
|
||||
defassert(:pathsubext, 'a.png', 'a.gif', '.png')
|
||||
defassert(:pathsubext, 'ruby.tar.bz2', 'ruby.tar.gz', '.bz2')
|
||||
defassert(:pathsubext, 'd/a.o', 'd/a.c', '.o')
|
||||
defassert(:pathsubext, 'foo', 'foo.exe', '')
|
||||
defassert(:pathsubext, 'lex.yy.o', 'lex.yy.c', '.o')
|
||||
defassert(:pathsubext, 'fooaa.o', 'fooaa', '.o')
|
||||
defassert(:pathsubext, 'd.e/aa.o', 'd.e/aa', '.o')
|
||||
|
||||
def root?(path)
|
||||
Pathname.new(path).root?
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue