Search code examples
rubyfilecross-platform

(Cross platform) check a file path is absolute without using Pathname library


I need a cross platform way to check if a given file path is absolute without using the Pathname library. The only library I'd wish to rely on for this would be File. It needs to be cross-platform and cross-implementation, so it should work regardless of it being Ruby MRI, JRuby, Rubinius… etc.

I wish to use pure Ruby, no C or Java. I can't think of a robust way.


Solution

  • def absolute_path?(path)
      File.expand_path(path) == path
    end