Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/file.rb

Overview

Core-Extensions on File

Class Method Summary (collapse)

Class Method Details

+ (Boolean) absolute_path?(path)

determine whether a String path is absolute.

Examples:

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

Parameters:

  • path (String)
    • a pathname

Returns:

  • (Boolean)


15
16
17
# File 'lib/core_ext/file.rb', line 15

def self.absolute_path?(path)
  false | File.dirname(path)[/\A([A-Z]:)?#{Regexp.escape(File::SEPARATOR)}/i]
end