Method: Path#replace_extension
- Defined in:
- lib/path/parts.rb
#replace_extension(ext) ⇒ Object Also known as: sub_ext
Replaces the last extension of path with ext. Handle both extensions with or without leading dot. Removes last extension if ext is empty?.
Path('main.c++').replace_extension('cc') # => #<Path main.cc>
77 78 79 80 |
# File 'lib/path/parts.rb', line 77 def replace_extension(ext) return without_extension if ext.to_s.empty? Path.new(@path[0..-extname.size-1] << Path.dotted_ext(ext)) end |