Module: Pathname::Extensions::Ext
- Defined in:
- lib/pathname/extensions/ext.rb
Overview
Changes extension of file
Class Method Summary collapse
Instance Method Summary collapse
-
#ext(new_extension = EMPTY_STRING) ⇒ Pathname
Replace the file extension with +new_extension+.
Class Method Details
.included(host) ⇒ Object
9 10 11 12 |
# File 'lib/pathname/extensions/ext.rb', line 9 def self.included(host) host.load_extensions :constants super end |
Instance Method Details
#ext(new_extension = EMPTY_STRING) ⇒ Pathname
Replace the file extension with +new_extension+. If there is no extension on the string, append the new extension to the end. If the new extension is not given, or is the empty string, remove any existing extension.
19 20 21 22 23 24 25 |
# File 'lib/pathname/extensions/ext.rb', line 19 def ext(new_extension = EMPTY_STRING) return dup if [HERE, UPPER].include? self unless new_extension == EMPTY_STRING new_extension = '.' + new_extension unless new_extension.match?(/^\./) end sub_ext(new_extension) end |