instance method
Pathname#sub_ext
(::string replacement) -> ::Pathname
sub_ext(repl)
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/pathname_builtin.rb, line 292
def sub_ext(repl)
ext = File.extname(@path)
# File.extname("foo.bar:stream") returns ".bar" on NTFS and not ".bar:stream"
# (see ruby_enc_find_extname()).
# The behavior of Pathname#sub_ext is to replace everything
# from the start of the extname until the end of the path with repl.
unless @path.end_with?(ext)
ext = @path[@path.rindex(ext)..]
end
self.class.new(@path.chomp(ext) + repl)
end
Return a pathname with repl added as a suffix to the basename.
If self has no extension part, repl is appended.
Example
Pathname.new('/usr/bin/shutdown').sub_ext('.rb') #=> #<Pathname:/usr/bin/shutdown.rb>