class File

Core-Extensions on File

Constants

ABSOLUTE_PATH_PATTERN
POSIX_ABSOLUTE_PATH_PATTERN
WINDOWS_ABSOLUTE_PATH_PATTERN

Public Class Methods

absolute_path?(path, platform = :default) click to toggle source

determine whether a String path is absolute. @example

File.absolute_path?('foo') #=> false
File.absolute_path?('/foo') #=> true
File.absolute_path?('foo/bar') #=> false
File.absolute_path?('/foo/bar') #=> true
File.absolute_path?('C:foo/bar') #=> false
File.absolute_path?('C:/foo/bar') #=> true

@param path [String] - a pathname @return [Boolean]

# File lib/core_ext/file.rb, line 15
def self.absolute_path?(path, platform = :default)
  pattern = case platform
            when :default then ABSOLUTE_PATH_PATTERN
            when :windows then WINDOWS_ABSOLUTE_PATH_PATTERN
            when :posix   then POSIX_ABSOLUTE_PATH_PATTERN
            else raise ArgumentError, "Unsupported platform '#{platform.inspect}'"
            end

  false | path[pattern]
end