Sha256: 2833ca68b89ddaef2794b911ae780b5ad4af4ea29d9ce9ae4e9143060389dfa3
Contents?: true
Size: 900 Bytes
Versions: 4
Compression:
Stored size: 900 Bytes
Contents
require 'facets/filetest/separator_pattern' module FileTest module_function # Predicate method for testing whether a path is absolute. # It returns +true+ if the pathname begins with a slash. def absolute?(path) !relative?(path) end # The opposite of #absolute? def relative?(path) while r = chop_basename(path.to_s) path, basename = r end path == '' end # List File.split, but preserves the file separators. # # FileTest.chop_basename('/usr/lib') #=> ['/usr/', 'lib'] # FileTest.chop_basename('/') #=> nil # # Returns Array of `[pre-basename, basename]` or `nil`. # # This method is here simply to support the #relative? and #absolute? methods. def chop_basename(path) base = File.basename(path) if /\A#{SEPARATOR_PATTERN}?\z/ =~ base return nil else return path[0, path.rindex(base)], base end end end
Version data entries
4 entries across 3 versions & 1 rubygems