Class: File

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

Class Method Summary collapse

Class Method Details

.absolute_path?(path) ⇒ Boolean

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:

  • - (String)

    a pathname

Returns:

  • (Boolean)


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

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