Method: String#without_extension

Defined in:
lib/cog/native_extensions/string.rb

#without_extension(ext) ⇒ String

Returns a copy of this string with the given extension removed. Does nothing if this string does not edit with the extension.

Parameters:

  • ext (String)

    file extension to remove from the end of this string

Returns:

  • (String)

    a copy of this string with the given extension removed. Does nothing if this string does not edit with the extension



36
37
38
39
40
41
# File 'lib/cog/native_extensions/string.rb', line 36

def without_extension(ext)
  return dup if ext.nil?
  ext = ext.to_s
  ext = '.' + ext unless ext.start_with? '.'
  end_with?(ext) ? slice(0..(-ext.length - 1)) : dup
end