ian
ian

Reputation: 12251

(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.

Upvotes: 2

Views: 315

Answers (1)

dbenhur
dbenhur

Reputation: 20398

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

Upvotes: 4

Related Questions