Sha256: a5125880fc51f0bd19ecf14c7c576be3a0f9b568879e6c81557e4b36f5de4161
Contents?: true
Size: 423 Bytes
Versions: 14
Compression:
Stored size: 423 Bytes
Contents
# Extension of existing File class. class << File # Returns the extension of a file. # path: the path of the file # dot: starting from the end, number of dots to count before cuting extension. def extname(path, dot = 1) pattern = (0...dot).inject('') { |pat,x| pat << '\.[^\.]+' } << '$' ext = File.basename(path).match(pattern).to_s ext.empty? ? "" : ext[1..ext.length] end end
Version data entries
14 entries across 14 versions & 2 rubygems