module Nuggets::File::ExtMixin
Public Instance Methods
chomp_ext(path) → aString
click to toggle source
Returns a copy of path
with its file extension removed.
# File lib/nuggets/file/ext_mixin.rb 35 def chomp_ext(path, ext = extname(path)) 36 path.chomp(ext) 37 end
chomp_ext!(path) → aString | nil
click to toggle source
Modifies path
in place as described for chomp_ext
, returning path
, or nil
if no modifications were made.
# File lib/nuggets/file/ext_mixin.rb 44 def chomp_ext!(path, ext = extname(path)) 45 path.chomp!(ext) 46 end
set_ext(path, new_ext) → aString
click to toggle source
Returns a copy of path
with its file extension removed and new_ext
appended. Like sub_ext
, but also applies when file extension is not present.
# File lib/nuggets/file/ext_mixin.rb 72 def set_ext(path, new_ext, ext = extname(path)) 73 chomp_ext(path, ext) << new_ext 74 end
set_ext!(path, new_ext) → aString
click to toggle source
Modifies path
in place as described for set_ext
, returning path
.
# File lib/nuggets/file/ext_mixin.rb 81 def set_ext!(path, new_ext, ext = extname(path)) 82 chomp_ext!(path, ext); path << new_ext 83 end
sub_ext(path, new_ext) → aString
click to toggle source
Returns a copy of path
with its file extension replaced with new_ext
(if present; see also set_ext
).
# File lib/nuggets/file/ext_mixin.rb 53 def sub_ext(path, new_ext, ext = extname(path)) 54 sub_ext!(_path = path.dup, new_ext, ext); _path 55 end
sub_ext!(path, new_ext) → aString | nil
click to toggle source
Modifies path
in place as described for sub_ext
, returning path
, or nil
if no modifications were made.
# File lib/nuggets/file/ext_mixin.rb 62 def sub_ext!(path, new_ext, ext = extname(path)) 63 path << new_ext if chomp_ext!(path, ext) 64 end